Sikau

Git & GitHub · Day 9 · about 30 min

Merge conflicts

When two changes touch the same line.

Two cooks, one recipe

You renamed the café to "Momo Corner" on main. A teammate renamed it to "Momo Palace" on their branch. Git can't guess which you want — so it stops and asks. That's a merge conflict, and it's completely normal.

Reading and resolving conflict markers

git switch -c rename
echo "<h1>Momo Palace</h1>" > index.html
git commit -am "Rename to Momo Palace"
git switch main
echo "<h1>Momo Corner</h1>" > index.html
git commit -am "Rename to Momo Corner"
git merge rename
cat index.html
echo "<h1>Momo Corner Palace</h1>" > index.html
git add index.html
git commit -m "Merge rename, keep both names"
git log --oneline --graph
  • git status lists conflicted files under "Unmerged paths".
  • Changes on *different* lines merge automatically — conflicts only happen when the same lines changed.
  • Changed your mind? git merge --abort puts everything back as it was before the merge.

The rest of this lesson

  • Preventing painful conflictsexplain
  • Anatomy of conflict markersexplain
  • Which part is yours?predict
  • Resolving a conflictorder
  • Your turnwrite code
  • Badge quizquiz
  • What you learnedrecap

Continue this lesson free — run real code in your browser

Continue with Google

See all 18 lessons of Git & GitHub