TK
All writing
Engineering

How to fix a Git merge conflict without panicking

Merge conflicts look scary and aren't. What a conflict actually is, how to read the <<<<<<< markers, resolving it step by step, and how to abort and start over if you get lost.

Tanveer Khan8 min read

The first merge conflict is a rite of passage, usually accompanied by mild panic. Don't. A conflict just means two branches changed the same lines and Git won't guess which you want — it's asking you to decide. Here's exactly how.

What you'll see

After a merge or rebase that conflicts, Git pauses and marks the clashing region in the file:

config.ts
text
<<<<<<< HEAD
const timeout = 5000;      // your branch's version
=======
const timeout = 10000;     // the incoming branch's version
>>>>>>> main
  • Everything between <<<<<<< HEAD and ======= is YOUR current branch.
  • Everything between ======= and >>>>>>> is the INCOMING change.
  • Your job: edit the region to the correct final result, then delete all three marker lines.

Resolve it

terminal
bash
git status           # lists files "both modified" — these have conflicts
# open each one, fix the <<<<<<< ... >>>>>>> regions to the final code
git add config.ts    # mark this file resolved
git commit           # (for a merge) finalise — or:
git rebase --continue  # (for a rebase) carry on

Your editor almost certainly has a conflict UI (VS Code shows 'Accept Current / Incoming / Both' buttons above each region). It's far less error-prone than hand-deleting markers — use it.

When you want to pick one side wholesale

terminal
bash
git checkout --ours config.ts     # keep YOUR version entirely
git checkout --theirs config.ts   # take THEIRS entirely
git add config.ts

Escape hatch: abort and start over

Lost or overwhelmed? You can always back out and return to before the merge/rebase — nothing is committed until you say so.

terminal
bash
git merge --abort     # undo an in-progress merge
git rebase --abort    # undo an in-progress rebase

A conflict is Git deferring a judgement call to you, not a disaster. Read the markers, edit to the right result, git add, continue — or abort and try again. After three or four, the panic is gone for good.