Understanding Git Merge Conflicts Through Conflict Markers
Merge conflicts sound more dramatic than they usually are. In most cases, Git is simply saying:
I found two valid versions of the same area, and I need a human to decide the final version.
This often happens when a feature branch and main both modify nearby lines in the same file. It can also happen when one branch edits something that another branch deletes.
What Conflict Markers Mean
When Git cannot merge automatically, it writes conflict markers into the file:
<<<<<<< HEAD
version from your current branch
=======
version from the branch being merged
>>>>>>> mainThe structure is simple:
<<<<<<< HEADstarts your current branch’s version=======separates the two versions>>>>>>> mainends the other branch’s version
Your job is to replace the whole marked section with the final content you actually want.
A Simple Example
Suppose the original file had this line:
Button color: blueYour feature branch changed it to:
Button color: greenMeanwhile, main changed it to:
Button color: redWhen Git tries to merge, it may produce:
<<<<<<< HEAD
Button color: green
=======
Button color: red
>>>>>>> mainGit is not saying either version is wrong. It is saying both branches changed the same area, and the final decision needs intent.
You could keep your version:
Button color: greenOr keep main’s version:
Button color: redOr choose something else:
Button color: purpleAfter deciding, remove the marker lines.
Conflicts Are Not Only Same-Line Edits
A common misunderstanding is that conflicts happen only when two branches edit the exact same line. That is not always true.
Conflicts can also happen when one branch edits a block and another branch deletes that same block.
For example, the original file had:
<section class="banner">
<h2>Holiday Sale</h2>
<p>Everything is 20% off this week.</p>
</section>Your feature branch changed the text:
<section class="banner">
<h2>Holiday Sale</h2>
<p>Everything is 30% off this week.</p>
</section>But main deleted the banner entirely:
Git cannot know whether the final page should keep the updated banner or remove the banner. So it may produce:
<<<<<<< HEAD
<section class="banner">
<h2>Holiday Sale</h2>
<p>Everything is 30% off this week.</p>
</section>
=======
>>>>>>> mainHere, the main side is empty because main deleted that block.
If the banner should stay, keep the block. If the banner was intentionally removed, delete the whole conflict block.
How To Resolve A Conflict
The process is usually:
git statusOpen the conflicted file and search for:
<<<<<<<Edit the file into the final version you want.
Then stage it:
git add path/to/fileAnd continue the merge:
git commitOr, during a rebase:
git rebase --continueThe Real Skill
Resolving conflicts is less about Git syntax and more about understanding intent.
Ask:
- Which branch represents the accepted behavior?
- Was this block intentionally changed or removed?
- Can both changes coexist?
- Is one change stale because the other branch moved the code forward?
Git shows the mechanical disagreement. The developer resolves the product decision.
Conflict markers are not errors to fear. They are just Git’s way of pausing before it guesses wrong.