Lesson 13 / 26

Resolving Merge Conflicts

What a conflict looks like and how to resolve one by hand.

When conflicts happen

A conflict occurs when two branches change the same lines of the same file differently. Git can't guess which version you want, so it pauses and asks you.

Conflict markers

Git inserts markers into the file. Edit it to keep the right content, then remove the markers.

<<<<<<< HEAD
const greeting = "Hi";
=======
const greeting = "Hello";
>>>>>>> feature/login

Finish the merge

Once every conflicted file is fixed, stage it and commit to complete the merge.

git add greeting.js
git commit -m "Merge feature/login, resolve greeting conflict"

Quick check: A merge conflict happens when...

  • Two branches change the same lines differently
  • You forget to run git status
  • A branch is deleted before merging
Answer

Two branches change the same lines differently — Git can auto-merge changes to different lines; overlapping edits need a human decision.