Today I was working in two separate branches in git and wrote a jQuery plugin that was useful to both branches. The problem was that I committed this new file along with changes to other files in order to use it. So I didn’t want to use cherry-pick to grab the commit because I didn’t want the other changes from that commit. There’s also the case where there are many commits involving that file in the other branch and you just want the most up to date version of that file. Turns out there’s a simple way to merge the latest version of a file (or even multiple files) from another branch into yours. Just follow this syntax:
git checkout <other branch name> <path(s) to file(s)>
Example of a single file:
git checkout new_feature public/javascripts/jquery.newplugin.js
Example for multiple files:
git checkout new_feature public/javascripts/jquery.newplugin.js public/stylesheets/jquery.newplugin.css
Then you can commit and you’ll have that file in your branch without causing any git ugliness.
Resource (and a little more detail) on Jason Rudolph’s blog.






