CurriculumBranching & MergingResolving Merge Conflicts
Lesson 4 of 580%
Beginner10 min+100 XP

Resolving Merge Conflicts

Merge conflicts occur when two branches change the same part of the same file in different ways. Git cannot decide which version to keep — it pauses the merge and asks you to resolve it manually. This is normal and nothing to fear.

01.Reading Conflict Markers

Git edits conflicted files and inserts markers. The section between "<<<<<<< HEAD" and "=======" is YOUR current version. The section between "=======" and ">>>>>>> feature/x" is the INCOMING version from the other branch. You must edit the file to the desired final state and remove ALL three marker lines completely.

index.html — CONFLICT
<html>
<body>
<<<<<<< HEAD (your version)
<h1>Welcome Back!</h1>
=======
<h1>Hello, World!</h1>
>>>>>>> feature/greeting (incoming)
</body>
</html>
<<<<<<< HEAD— Your version
=======— Divider
>>>>>>> branch— Incoming

02.The Resolution Process Step by Step

Step 1: Run git status to see every conflicted file. Step 2: Open each file in your editor and find the conflict markers. Step 3: Edit to your desired final result — keep one version, the other, or combine both. Step 4: Remove every <<<<<, =====, and >>>>> marker line. Step 5: git add the resolved file. Step 6: git commit to complete the merge.

Git's Three Areas
📁
Working Dir
Your files
→ git add
📋
Staging Area
Prepared
→ git commit
🗄️
Repository
.git/ history

Commands

commands — click to reveal output
$
git merge feature/login
Attempt merge — conflicts pause it
▼ show output
$
git status
See all conflicted files
▼ show output
$
# Edit conflicted files in your editor
Find markers, choose/combine content, remove ALL markers
$
git add index.html style.css
Mark files as resolved after editing
$
git commit
Complete the merge — Git pre-fills the message
▼ show output
$
git merge --abort
Changed your mind? Abort and go back to before the merge
KNOWLEDGE CHECK

After manually editing a conflicted file and removing all markers, what is the next step?

Rate this lesson:
PreviousNext Lesson