Lesson 4 of 8

Merge Conflicts

When two branches change the same line, cannot tell which version you want and asks you to choose. Learn to read conflict markers and resolve them.

When git can't auto-merge, it stops and marks the conflicting region in the file with conflict markers. Your job: open the file, pick (or combine) the versions, delete the markers, stage, commit. That's the whole procedure.

Text
<<<<<<< HEAD
const greeting = "Hello, world!";
=======
const greeting = "Hi there!";
>>>>>>> feature-branch

The part between <<<<<<< and ======= is YOUR side (current branch).
The part between ======= and >>>>>>> is THEIR side (branch being merged).
Bash
git merge feature-branch
# CONFLICT (content): Merge conflict in greeting.js

# 1. Open greeting.js, edit it to the final version,
#    removing all <<<< ==== >>>> markers.
# 2. Then:
git add greeting.js
git commit               # completes the merge

# To cancel the merge and go back to how things were:
git merge --abort
Finished reading?Mark it done to track your progress.

Tip: use the ← and → keys to move between lessons.