How can I copy files from a branch to another using git?

I have a git repository with two branches: master and gh-pages. If I want to copy a file foo from master to gh-pages without merging them. What command should I use? Many thanks.


Solution 1:

You can:

git checkout gh-pages
git checkout master foo
git commit -m 'Add file foo to gh-pages.'

Solution 2:

If you want to compare all the diffs between 2 branches: you can use git difftool master gh-pages or git difftool <SHA1 of gh-pages> .

If you want to get diff for specific list of files follow this:

git diff master gh-pages -- path/to/file