Quest 05
Merge conflicts
Two branches changed the same line, and git will not guess who is right. A conflict is not an error. It is git asking you a question.
Goal#
Read conflict markers, resolve a conflict calmly, finish the merge, and know how to back out.
When git asks#
Git merges changes to different lines on its own. When both branches changed the same lines, it stops and marks the file:
<<<<<<< HEAD
The cat is called Mittens.
=======
The cat is called HEAD.
>>>>>>> rename
She likes boxes.
Between <<<<<<< HEAD and ======= is your side: the branch you are on. Yes, that is her name in the marker; she did not plan it. Between ======= and >>>>>>> rename is the branch you are merging in. Everything outside the markers merged fine.
Resolve it#
git statuslists the files in conflict ("both modified").- Edit each one: keep what is right, which can be one side, the other, or a mix. Delete all three marker lines.
git addthe file to mark it resolved.git committo finish the merge. Git writes the message for you.
Changed your mind halfway? git merge --abort puts everything back as it was before the merge.
Quest 05#
quest start 5
main calls the cat Mittens. The rename branch calls her HEAD. Merge rename into main, and resolve the conflict so the cat is called HEAD. Then quest check.
Check it works#
name.txthas no markers and saysThe cat is called HEAD.git log --oneline --graphshows a merge commit joining both branches, andquest checkpasses.
Exercise#
Start the quest again and resolve it the other way: keep Mittens. Then run git merge --abort in the middle of another try and check with git status that nothing changed. Knowing the exit is half the confidence.
More to try
git config --global merge.conflictStyle zdiff3also shows the original line, from before either side changed it. Try the quest with it on.- Editors such as VS Code show buttons over each conflict: "Accept Current", "Accept Incoming", "Accept Both". Match each to the markers.
Quest 05
quest start 5 # ...fix it with real git... quest check
Mark it done once quest check shows every line as PASS. Your progress stays in this browser.