Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19.7k points)

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?

1 Answer

0 votes
by (62.9k points)

You can simply perform fetch which will download all the changes done from your remote repository to your local repository and then check out to that one file in the following way:

git fetch

git checkout -m <revision> <yourfilepath>

git add <yourfilepath>

git commit

Regarding the git checkout command: <revision> - a branch name, i.e. origin/master <yourfilepath> does not include the repository name (that you can get from clicking copy path button on a file page on GitHub), i.e. README.md

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...