Resolving
Merge Conflicts
Learn how Git detects conflicting changes and how to read conflict markers, choose the right code, and complete a clean merge.
What Is a Merge Conflict?
A merge conflict happens when two branches change the same lines of the same file. Git cannot automatically decide which version to keep, so it pauses and asks you to resolve the disagreement.
When Do Conflicts Happen?
Why Resolving Conflicts Matters
The Three Conflict Markers
Anatomy of a Conflict Block
Ours vs. Theirs: Key Distinction
| Ours (HEAD) | Theirs (Incoming) | |
|---|---|---|
| Position | Above ======= | Below ======= |
| Source | Your current branch | The branch being merged in |
| Marker | <<<<<<< HEAD | >>>>>>> branch |
| Analogy | "What I wrote" | "What they wrote" |
Three Resolution Strategies
How to Resolve Step by Step
Example 1: Accept Ours
Your team decided the main branch has the correct color. Remove the incoming code and all markers:
Example 2: Accept Theirs
After reviewing, the feature branch has a better implementation. Keep the incoming code:
Example 3: Combine Both
Sometimes both sides add different code you want to keep. Merge the logic manually:
The Full Git Workflow
Common Mistakes to Avoid
Summary: Resolution at a Glance
| Step | Action | Result |
|---|---|---|
| 1. Detect | Run git merge | Git reports conflicted files |
| 2. Locate | Search for <<<<<<< | Find each conflict block |
| 3. Decide | Read ours vs. theirs | Choose strategy |
| 4. Edit | Keep desired code | Delete all markers |
| 5. Finalize | git add + git commit | Merge complete ✓ |
Question 1 of 5
Which marker line separates the two conflicting versions inside a conflict block?
Question 2 of 5
You are on the main branch and run git merge feature. Git reports a conflict in utils.js. You open the file and see:
<<<<<<< HEAD
const MAX = 100;
=======
const MAX = 200;
>>>>>>> feature
If you want to accept the feature branch's value, what should the resolved file contain?
Question 3 of 5
After manually editing a conflicted file, what two Git commands do you need to run to complete the merge?
Question 4 of 5
What happens if you leave conflict markers in a JavaScript file and try to run it?
Question 5 of 5
You see this conflict in config.js:
<<<<<<< HEAD
const PORT = 3000;
=======
const HOST = "localhost";
>>>>>>> feature
The two branches added different constants on the same line.
What is the best resolution in this case?