Merge conflicts

Play this lesson

Git stops and asks

A branch is a separate line of commits (save points), and merging combines one branch into another. Usually it just works.

But today Kai types git merge feature/hard-mode and Git prints:

CONFLICT (content): Merge conflict in balance.json
Automatic merge failed; fix conflicts and then commit the result.

Don't panic. Nothing is broken or lost. Git just needs a human decision.

Why conflicts happen

Git merges line by line. If Kai changed line 4 of a file and Remy changed line 9, Git combines both with no fuss. That covers most merges.

A merge conflict happens when both branches changed the same lines, or one person deleted a file the other edited. Git can't know which version is right, so it stops and asks.

Conflicts can also appear during git pull, because pull is a download plus a merge.

Quick check

If Kai only edits ship.js and Remy only edits shop.js, merging their branches causes a conflict.

Show the answer

False

Different files means different lines, so Git combines both changes by itself. Conflicts only happen when both change the same lines.

The conflict markers

Git writes both versions into the file, between conflict markers:

<<<<<<< HEAD
"sprigHealth": 12,
=======
"sprigHealth": 8,
>>>>>>> feature/hard-mode

The top part is your current branch. HEAD means "where I am now". The bottom part is the incoming branch. Your job: edit the file so it holds the right final version, and delete all three marker lines.

Choose or combine

There are three ways out. Many code editors show buttons for them right above the markers.

Fix the conflict

balance.json
{<<<<<<< HEAD  "sprigHealth": 12,=======  "sprigHealth": 8,>>>>>>> feature/hard-mode  "snailSpeed": 1}

The team agrees normal mode keeps Sprig at 12 health. Hard mode will get its own setting later. What should lines 2 to 6 become?

  1. Just "sprigHealth": 12, with all three marker lines deleted
  2. Leave them as they are, the game will pick one
  3. Just "sprigHealth": 8, keeping the ======= line
Show the answer

Just "sprigHealth": 12, with all three marker lines deleted

Keep the agreed value and remove every marker line. Markers left in balance.json make it broken JSON, so Garden Defense couldn't load its numbers at all.

Test, then finish

Before finishing, test: run the game and play the part that changed. A file can look fine and still be wrong. One leftover ======= in a JSON file crashes the game on load.

Then tell Git the conflict is solved and finish the merge:

git add balance.json
git commit -m "Merge hard mode, keep Sprig at 12"

Want to back out halfway? git merge --abort cancels the merge and puts everything back as it was.

Quick check

Once the conflict markers are gone, the merge must be correct, so there's no need to play the game.

Show the answer

False

Removing markers only makes the file readable. You might have kept the wrong value, or two changes might clash in a way only playing reveals. Always test before committing.

Fewer conflicts

AI can help, you decide

An AI agent can help with conflicts. Ask Claude Opus 5.5: "Explain both sides of this conflict in balance.json and suggest a fix."

But you still read its answer and play the game, because only the team knows which number was meant to win.

Bolt says: Next lesson: pull requests, where the team checks every change before it is merged.

Fact-checked 9 October 2026