Merge conflicts, calmly
Git asks you a question. You answer it. That is all a conflict is.
1 Learn the idea
A merge conflict looks scary, but nothing is broken and nothing is lost. It simply means: both branches changed the same part of the same file, and git refuses to guess which version you want.
Reading the markers
<<<<<<< HEAD Soup of the day: lentil ======= Soup of the day: pumpkin >>>>>>> autumn
- Between
<<<<<<< HEADand=======: your version (the branch you are on). - Between
=======and>>>>>>> autumn: their version (the branch being merged in). - Your job: edit the file into the version you want and delete all marker lines.
The recipe
git status— see which files are "both modified".- Open each file, pick/combine the content, remove the markers.
git add <file>— tells git "this one is resolved".git commit— finishes the merge with a merge commit.
2 Watch it happen
Press Play or use → to step through. Watch the graph as each command runs.
Read this demo as text
$ git log --oneline --all
Both
mainandautumnchanged the same line ofmenu.txt— tomato became lentil on one side, pumpkin on the other.$ git merge autumn
CONFLICT! Git merged what it could, but stops at
menu.txtand asks you to decide. The merge is paused, not failed.$ git status
git statusis your map during a merge: it lists the unmerged paths ("both modified") and tells you what to do next.$ cat menu.txt
The file now contains both versions, wrapped in conflict markers: yours (HEAD) on top, theirs (autumn) below.
$ edit menu.txt "Soup of the day: pumpkin & lentil"
We write the version we actually want — here, a combination — and remove every marker line.
$ git add menu.txt
git addmarks the file as resolved. Look at the staging area: the conflict is gone.$ git commit -m "Merge autumn menu"
The merge commit is created with two parents. Conflict resolved — nothing was lost along the way.
$ git log --oneline
History shows both soup commits joined by our merge commit.
- Conflicts only happen when both sides changed the same lines (or one edited a file the other deleted).
- Changes to different files, or different parts of a file, merge automatically.
- Small, frequent merges mean small, easy conflicts.
git statusSee which files are in conflictgit add <file>Mark a conflicted file as resolvedgit commitConclude the mergegit merge --abortCancel and go back to before the merge3 Check your understanding
When does git report a merge conflict?
In a conflicted file, what is between <<<<<<< HEAD and =======?
You edited the file and removed the markers. What tells git the conflict is resolved?
Halfway through resolving, you realise you merged the wrong branch. Best move?
4 Practice for real
Settle the theme debate
Merge dark-mode into main. It will conflict on theme.txt. Resolve it so the file says theme: dark, and finish the merge.