Practical guideTested1 min read
How to fix a Git merge conflict step by step
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
>>>>>>> featFix
- Open the file and keep the lines you want. Delete the three marker lines.
git add fgit commit -m "merged"
Want to stop and start over?
git merge --abort puts the branch back as it was before the merge.
Common mistakes
- Committing with the marker lines still in the file. Search the file for
<<<<<<<before you commit. - Running
git commitwithoutgit add f. Git still sees the file as unresolved.
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