Jason Rudolph has a great blog post on merging files from one branch to another in git. In most cases you probably want to cherry-pick commits, however for a quick and fast solution this is pretty cool:
$ git branch * master twitter_integration $ git checkout twitter_integration app/avatar.rb $ git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # new file: app/models/avatar.rb # $ git commit -m "'Merge' avatar code from 'twitter_integration' branch" [master]: created 4d3e37b: "'Merge' avatar code from 'twitter_integration' branch" 1 file changed, 72 insertions(+), 0 deletions(-)
Two things i noticed about this method:
- Wildcards and directories work too. So instead of getting a single file from another branch you can also do a git checkout branch * or git checkout branch path/to/directory
- All paths are relative, so if you’re not in the root of a repo, you need to give the relative path to your file(s).