Solving merge conflict in git¶
We want to merge a branch to the master branch but we have merge conflicts. What to do?
Clone the repository:
git clone
or just git fetch
if you already have a cloned repository to be up-to-date.
Checkout the faulty branch faulty-branch
:
git checkout faulty-branch
Rebase the faulty branch on the latest changes in the master branch (sometimes, it is not called master but dev or some other name) git rebase origin/master
That should trigger the merge conflicts. In the faulty files we have conflicts indicated by lines such as:
<<<<<<< HEAD
master version
=======
faulty-branch version
>>>>>>> commit number
We need to edit these files manually and resolve the conflicts. This means that you open the file with the edtior of your choice, look for the markers like the ones above, and bring the file into the state that you want to have it in. So afterwards there should be no conflict indicators anymore, because you removed them.
Then git add/rm
all files where merge conflicts have now been resolved
Continue/finalize the rebase:
git rebase --continue
Force push the change to the remote branch faulty-branch
:
git push -f origin