← Learning Hub
Intermediate

Merge Conflicts

A conflict happens when two branches change the same lines of the same file. Git can't guess which version is right, so it asks you.

A conflict happens when two people change the same lines differently - Git can't guess which version is right, so it asks you. Conflicts are normal in team work; the markers show both versions, and you choose the final text.

Example
git merge price-update
# CONFLICT (content): Merge conflict in cart.js
# Automatic merge failed; fix conflicts and then commit the result.

Open the file. Git marks both versions:

Example
<<<<<<< HEAD
const GST = 0.18;
=======
const GST = 0.12;
>>>>>>> price-update
  • Between <<<<<<< HEAD and ======= is your current branch's version.
  • Between ======= and >>>>>>> is the incoming branch's version.
  • Edit the file to the final correct code and delete all three marker lines.
Example
const GST = 0.18;          // the final, correct line

git add cart.js            # mark the conflict as solved
git commit                 # finish the merge

Tips

  • VS Code shows buttons: Accept Current, Accept Incoming, Accept Both, and a 3-way merge editor.
  • Changed your mind? git merge --abort returns to before the merge.
  • Fewer conflicts: pull often, keep branches short-lived, and make small commits.
A conflict is not an error - it's Git asking a question. Read both versions, talk to whoever made the other change if unsure, and keep both people's intent.
Key points
  • Conflicts mark both versions with <<<<<<<, ======= and >>>>>>>.
  • Edit to the correct final text, then add and commit.
  • Pull often to keep conflicts small.

📝 Test yourself

1. When does a merge conflict happen?
2. After fixing a conflicted file, what do you do?
3. Fill in the command that cancels a merge in progress:
git merge --