How to Resolve a Merge Conflict in Git
A merge conflict happens when Git can't automatically combine changes because the same lines were edited differently on both sides being merged.
Published September 29, 2026
A merge conflict happens when two branches changed the same lines. Git marks the conflict in the file; you edit it to the correct result, stage it and finish the merge.
How it works
Conflict markers show both versions: <<<<<<< (your side), ======= and >>>>>>> (their side). Remove the markers and keep the right code.
Tools like git mergetool or your IDE show a three-way view.
Try it
git merge feature
CONFLICT (content): Merge conflict in app.js
<<<<<<< HEAD
const a = 1
=======
const a = 2
>>>>>>> feature
Practical examples
Find conflicted files
git status
git diff --name-only --diff-filter=UFinish after editing
git add app.js
git commitAbort the merge
git merge --abortTake one side entirely
git checkout --ours app.js
git checkout --theirs app.jsCommon mistakes
- Committing with conflict markers left in the file.
- Choosing a side without understanding both changes.
- Not running tests after resolving.
Key takeaways
- Edit markers, git add, then commit.
- --abort undoes the merge.
- Test afterwards.
FAQ
Why do conflicts occur?
Both branches edited the same lines or one deleted what the other changed.
How can I reduce them?
Pull often and keep branches short-lived.