KKAIROSافتح التطبيق
Practical guideTested1 min read

How to fix a Git merge conflict step by step

Published:

Advertisement

Why it happens

Two branches changed the same line of the same file. Git cannot pick one for you, so git merge feat stops with CONFLICT (content): Merge conflict in f and Automatic merge failed; fix conflicts and then commit the result.

The file then holds markers around both versions:

<<<<<<< HEAD
main
=======
feat
>>>>>>> feat

Fix

  1. Open the file and keep the lines you want. Delete the three marker lines.
  2. git add f
  3. git commit -m "merged"

Want to stop and start over?

git merge --abort puts the branch back as it was before the merge.

Common mistakes

Is a conflict a sign I did something wrong?

No. It only means two people, or two branches, edited the same spot.

How do I see which files are in conflict?

git status lists them under "Unmerged paths".

Source: https://git-scm.com/docs/git-merge

Full kit: Git Survival Kit