A good[ish] website
Web development blog, loads of UI and JavaScript topics
You probably knew that a branch can be "checked out" with the git checkout branch-name
, but interestingly, a single file or a whole folder can also be checked out from another branch.
Say, you want to pull a folder or a file from a feature branch to a master, the workflow would be as follows.
First, checkout the wanted branch:
$ git checkout master
Then checkout the needed file or folder from the other branch:
$ git checkout feature-branch -- src/js/some-file.js
Now Git shows a dirty tree:
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: src/js/some-file.js
Git checkout a folder is the same pretty much:
$ git checkout feature-branch -- src/js/
Then commit in normal fashion:
$ git commit -m "Get folder from another branch"
Comments would go here, but the commenting system isn’t ready yet, sorry. Tweet me @hiljaa if you want to make a correction etc.