The calm four-step procedure
A conflicted merge feels broken, but structurally it is just a paused merge: Git has stopped mid-operation and is waiting for exactly two things from you — fixed files, then a commit. Knowing the fixed procedure is what turns a five-alarm moment into two calm minutes, which is why every working engineer has it memorized:
- See the damage report.
git statuslists each conflicted file underUnmerged pathsasboth modified. Only those files need you. - Edit each conflicted file. Keep your side, keep theirs, or write a combination, then delete the three marker lines. The file should end up looking exactly how you want it to look, markers are scaffolding, not content.
- Stage the fixed file:
git add cake.txt. In a conflict, add carries the meaning "this file is resolved." - Finish the merge:
git commit. Git pre-fills a message likeMerge branch 'brown-butter', accept it and you're done.
$ git add cake.txt
$ git commit
[main 9c8b7a6] Merge branch 'brown-butter'The most common beginner mistake is step 2 half-done: fixing the text but leaving a stray >>>>>>> line in the file, which then gets committed as garbage. Always search the file for <<<, ===, and >>> before staging.
Code exercise · bash
Your turn to perform step 2 by hand. The conflicted file contained the block from lesson 6-1, and you've decided the incoming side wins: the middle line should be "Add brown butter". Build the final resolved cake.txt (three lines: Preheat oven to 180C, Add brown butter, Bake for 25 minutes) with no marker lines, then print it with cat.
Finish the merge. You've already edited cake.txt, kept the line you wanted, and deleted the marker lines.
Step 1/3: Check which files are still marked as conflicted.
The escape hatch, and avoiding conflicts
Mid-conflict and overwhelmed? You can always back out completely:
$ git merge --abort
This cancels the merge and returns the repository to the exact state before you ran git merge. Nothing lost, breathe, try again later.
You can't prevent every conflict, but you can keep them small:
- Merge often. Short-lived branches touch fewer lines, so they collide less.
- Keep commits focused (lesson 2-3's habit pays off here, small changes conflict in small ways).
- Talk to your team before two people rewrite the same file.
Quiz
You've edited the conflicted file and deleted the markers. How do you tell Git the conflict is resolved and complete the merge?
Problem
You're mid-conflict and decide to cancel the whole merge and return to the state before it started. What is the full command?