Resolving Merge Conflicts
You'll learn how to read Git's conflict markers, choose the correct changes, and finalize the merge.
Understanding Conflict Markers
When Git can't automatically merge changes (as introduced in the previous lesson), it marks the conflicted sections in your files with special markers:
<<<<<<< HEAD
Your current branch's version of the code
=======
The incoming branch's version of the code
>>>>>>> feature-branch
Think of these markers like a split-screen comparison. Everything between <<<<<<< HEAD and ======= is what exists in your current branch. Everything between ======= and >>>>>>> feature-branch is what's coming from the branch you're merging in.
Resolving the Conflict
Your job is to decide which version to keep—or combine both intelligently. Open the conflicted file in your editor and:
- Read both versions carefully to understand what each branch changed
- Edit the section to reflect the desired final state
- Remove all conflict markers (
<<<<<<<,=======,>>>>>>>)
The file should look normal when you're done, as if the conflict never existed.
Completing the Merge
Once you've resolved all conflicts:
- Stage the resolved files with
git add <filename>(orgit add .for all) - Commit the merge with
git commit(Git will provide a default merge commit message)
The staging step tells Git "I've resolved this conflict and this is the correct version." The commit finalizes the merge, creating a new commit that incorporates both branches' histories.
Key Takeaway: Resolving merge conflicts requires manually editing files to remove conflict markers and choose the correct changes, then staging with git add and committing to complete the merge.