How to Merge Specific Files From Another Branch

17 Jan 2013

A simple git checkout will do!

# syntax :
$ git checkout source_branch <paths>

# real example:
$ git branch
* master
  twitter_integration
$ git checkout twitter_integration app/models/avatar.rb test/unit/models/avatar_test.rb
$ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   new file:   app/models/avatar.rb
#   new file:   test/unit/models/avatar_test.rb
#
$ git commit -m "'Merge' avatar code from 'twitter_integration' branch"
[master]: created 4d3e37b: "'Merge' avatar code from 'twitter_integration' branch"
2 files changed, 72 insertions(+), 0 deletions(-)
create mode 100644 app/models/avatar.rb
create mode 100644 test/unit/models/avatar_test.rb

Reference