You probably knew that a branch can be "checked out" with the command
git checkout <branch-name>, but interestingly enough, 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 into 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 feature branch with the following command:
$ git checkout feature-branch -- src/js/some-file.js
Now if you check the status, 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
Checking out 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.