Is it possible to pull just one file in Git?

Audrius Meskauskas picture Audrius Meskauskas · Apr 26, 2013 · Viewed 263.7k times · Source

I am working on a Git branch that has some broken tests, and I would like to pull (merge changes, not just overwrite) these tests from another branch where they are already fixed.

I know I can do

git pull origin that_other_branch

but this will attempt to merge lots of other files, for that I am not yet ready.

Is it possible to pull and merge only the specified file (and not everything) from that another branch?

This is not a duplicate of Git pull request for just one file as all answers to that question are how to revert the locally changed file to the repository version, without changing any branches.

Answer

Chris picture Chris · Aug 23, 2014

Here is a slightly easier method I just came up with when researching this:

git fetch {remote}
git checkout FETCH_HEAD -- {file}