Resolving Merge Conflicts
Understand why conflicts happen and work through them calmly, step by step
Merge conflicts feel scary the first time, but they're routine — a normal part of collaborating. A conflict simply means Git found two different changes to the same lines and needs you to decide which to keep. Nothing is broken.
Why Conflicts Happen
Git merges changes automatically when they touch different lines. A conflict occurs only when the same lines were changed differently on both branches — Git won't guess which version is correct.
main: const greeting = "Hello"
feature: const greeting = "Hi there"
→ both edited the same line → CONFLICT
If one branch edited line 5 and the other edited line 50, Git merges them cleanly with no conflict. Conflicts are about overlap, not just "both branches changed the file."
What a Conflict Looks Like
When you merge and hit a conflict, Git stops and tells you:
git merge feature/greeting
Auto-merging src/app.js
CONFLICT (content): Merge conflict in src/app.js
Automatic merge failed; fix conflicts and then commit the result.
Open the file — Git has inserted conflict markers showing both versions:
<<<<<<< HEAD
const greeting = "Hello"
=======
const greeting = "Hi there"
>>>>>>> feature/greeting
Read the markers like this:
<<<<<<< HEAD→ everything below is your current branch (where you are)=======→ the divider>>>>>>> feature/greeting→ everything above is the incoming branch
Resolving It
To resolve, edit the file so it contains exactly what you want the final result to be — then delete all three markers. You might keep one side, the other, or combine them:
const greeting = "Hi there"
Then stage the resolved file and commit to complete the merge:
git add src/app.js
git commit # completes the merge (Git pre-fills a message)
conflict raised → edit file → remove markers → git add → git commit → done
During a conflict, git status lists every file still "unmerged". When that
list is empty, all conflicts are resolved and you can commit. It's your
checklist.
Escaping a Merge
If a merge goes sideways and you'd rather start over, abort it. This returns you to the exact state before you ran git merge:
git merge --abort
Nothing is lost — it's as if the merge never happened.
Conflicts get worse the longer a branch drifts from main. Pulling main
into your feature branch frequently (or keeping branches short-lived) means
fewer, smaller conflicts.