How to merge single files with git?



So my partner and I are complete Git beginners and are having a hard time just following the terminology let alone making any sense out of the docs and online guides.

Here’s the situation:

We have a git repo with a bunch of files. We both started with the latest master copy. My partner then made a bunch of changes on a new branch, whereas I made all my changes on my master branch.

Right now we want to combine our changes. We both worked on separate files, so really we only need to ‘pull’ (not sure of the terminology) each other’s single file that we worked on.

Any help would be greatly appreciated. Thanks!


As an example, let’s say there are 5 files: A, B, C, D, and E

We both pulled all the files. Partner worked on A in a separate branch. I worked on B on my master branch. Now I want to give him my B changes and to get his A changes. Thanks again


I think you just have to apply git merge.

Before that,

1) Commit and push all the changes of the branch to the remote. Lets say if your branch name is partner and assuming you are working on mac, these are the below terminal commands to commit your parner’s stuff.

git commit -m "Changed something and added something"
git push origin partner

Remote is upto date with your partner branch changes.

2) On the master branch, apply a merge

git fetch origin 
git merge origin/partner

This means you are merging the partner remote branch to the local master branch.

3) Changes are merged into the local master branch. Now push all the changes to remote master (some times you need to do a commit if there any local changes)

git push origin master

Hope this helps you.


Answered By – sha

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More