On this page
How to Resolve a Git Merge Conflict
Resolve a Git merge conflict step by step: read the conflict markers, choose the right change, and finish the merge — without losing work.
Quick answer
- A merge conflict happens when two changes edit the same lines and Git can’t decide which to keep.
- Resolve it by finding the conflict markers, choosing the correct version, and committing the result.
- The key rule: don’t guess — read both sides and keep what’s actually correct.
What a conflict is
Git merges changes automatically when they touch different lines. When two branches edit the same lines differently, Git stops and asks you to decide. It marks the file with conflict markers and leaves it for you to resolve.
Step 1 — Find the conflicted files
git statusGit lists files as “both modified.” How to verify it worked: you can see exactly which files need attention.
Step 2 — Read the conflict markers
Open a conflicted file. You’ll see:
<<<<<<< HEAD
const limit = 100;
=======
const limit = 50;
>>>>>>> feature/rate-limitThe section between <<<<<<< HEAD and ======= is your current branch’s version; between ======= and >>>>>>> is the incoming branch’s version.
Step 3 — Decide and edit
Replace the whole marked block with the correct version — yours, theirs, or a combination of both. Delete the markers entirely.
const limit = 75;How to verify it worked: no <<<<<<<, =======, or >>>>>>> markers remain in the file.
Step 4 — Mark it resolved and finish
git add path/to/file
git commitFor a rebase conflict, finish with git rebase --continue instead of committing.
Step 5 — Verify nothing was lost
Run your tests and grep for any leftover markers:
grep -rn "<<<<<<<" .How to verify it worked: no markers remain and the test suite passes — a successful merge, not just a completed one.
Where this bites vibecoders
The dangerous resolution is “delete one side to make the marker go away” — that silently discards work. An AI assistant may resolve a conflict by picking a side without understanding which behavior is correct. The rule is the same as any review: understand what each side changed and why before choosing. When both sides matter, merge them; when unsure, ask whoever wrote the other side.
Where AI coding assistants get this wrong
- “Resolving” by deleting one side blindly to clear the markers.
- Picking the wrong side because it doesn’t understand the intent of either change.
- Leaving conflict markers in a file and committing it.
- Resolving correctly in one file and missing another.
Checklist
- List all conflicted files with
git status. - Read both sides before choosing.
- Remove all conflict markers completely.
- Run tests after resolving.
- Grep for leftover markers before committing.
FAQ
What causes a merge conflict?
Two branches changing the same lines, or one side editing lines the other deleted. Git can merge independent changes automatically; it only pauses when it can’t determine the right result.
How do I avoid conflicts?
Keep branches short-lived, pull or rebase frequently, and make focused changes. Conflicts are a normal part of collaboration — the goal is to make them small and rare, not to eliminate them entirely.
What if I abort the merge?
git merge --abort (or git rebase --abort) returns you to the state before the merge started. Use it when the conflict is bigger than expected and you want to start over with a clearer plan.