DEV Community

Cover image for Solving Merge Conflicts in Git | Conflicts between two branches on the same file [ Command Line ]
Andrew W Mandillah
Andrew W Mandillah

Posted on • Edited on

Solving Merge Conflicts in Git | Conflicts between two branches on the same file [ Command Line ]

While collaborating on github , and you update the same file at the same time , you have conflicts between two branches on the same file upon merge!
Let's take a scenario , where you have main branch and updated_branch and the updated_branch has remote changes on the same file as your local main branch.
TLDR;
git merge updated_branch throws an error

merge Error Image

It's easy . Let's solve it :
1. Checkout the main branch
git checkout main
2. Merge specific files from the updated_branch :
git checkout other_branch_name -- path/to/file
Replace other_branch_name with the actual name of the other branch and path/to/file with the path to the file you want to update.
3.Commit the Changes:
git commit -m "Update file from updated_branch_name"
4.Push Changes (If Necessary):
git push origin master

Finally , try the initial merge operation.
git merge updated_branch

Voila ! Everything should be fine now !!

Top comments (0)