Chapter 48: Git Merge Conflicts

Git Merge Conflicts (the moment almost every developer hates the first time they see it, but eventually learns to handle calmly)

This is not a command — it’s a situation Git puts you in when it cannot automatically decide how to combine two different versions of the same file.

Many beginners panic the first time they see those ugly markers:

text

They think: “My code is broken forever” “Git is angry at me” “I ruined everything”

But the truth is: merge conflicts are normal, expected, and actually healthy. They mean two people changed the same lines of the same file in different ways — Git is politely saying:

“I don’t know which version is correct — you decide.”

Today I’m going to explain merge conflicts like I’m sitting right next to you when it happens for the first time — very slowly, with real examples, step-by-step resolution, what the markers mean, common patterns in 2026, and how professional teams handle them without stress.

1. When & Why Do Merge Conflicts Happen?

A conflict occurs when Git tries to merge two branches and finds that the same line(s) were changed differently in both branches since their common ancestor.

Typical situations in 2026:

  • You and teammate both edited the same function in app.js
  • You fixed a bug in main, teammate added a feature in feature/new-ui — both touched the same block
  • You rebased/cherry-picked/amended → history changed → Git sees “different” changes
  • Someone force-pushed a branch you were working on

No conflict = Git can auto-merge cleanly Conflict = Git stops and asks you to choose / combine

2. Realistic Example – Let’s Create & Resolve a Conflict Step by Step

Setup (copy-paste ready)

Bash

Initial commit (common ancestor)

Bash

Step 1 – Create two branches from same point

Bash

Step 2 – Make conflicting changes on both branches

On feature/add-login

Bash

On feature/add-search

Bash

Step 3 – Try to merge → conflict!

Switch to main and merge one branch:

Bash

Now merge the other:

Bash

Git says:

text

Step 4 – Look at git status

Bash
text

Step 5 – Open the conflicting file (README.md)

You see Git inserted ugly markers:

Markdown

What the markers mean:

text

Step 6 – Resolve the conflict manually

Open README.md in any editor (VS Code is best — it highlights conflicts beautifully)

Decide what you want:

Option A – Keep both (combine)

Markdown

Option B – Keep only one

Markdown

Option C – Rewrite completely

Markdown

Remove all markers (<<<<<<<, =======, >>>>>>>)

Save file.

Step 7 – Tell Git you resolved it

Bash

Step 8 – Finish the merge

Bash

Git auto-fills message:

text

You can edit or keep it. Save → merge complete.

Now:

Bash
Bash

4. Modern Tools That Make Conflicts Less Painful (2026 reality)

  • VS Code built-in merge editor — 3-way view (base + yours + theirs) + accept current / incoming / both buttons
  • GitKraken / Fork / Tower — visual conflict resolver (drag-drop hunks)
  • Meld / Beyond Compare / Araxis Merge — external 3-way diff tools (set with git config –global merge.tool meld)

5. Common Conflict Patterns & Quick Fixes

Conflict type Typical markers look like Quick resolution tip
Same line changed differently <<<<<<< HEAD your line ======= their line >>>>>> branch Choose one or combine
One side added lines, other deleted <<<<<<< HEAD your new lines ======= (empty) >>>>>> branch Decide whether to keep addition or deletion
File renamed on one side, edited on other CONFLICT (modify/delete) git rm or git add the file as appropriate
Both sides renamed file differently CONFLICT (rename/rename) Manually rename to final name & git add

6. Prevention Tips (pro habits 2026)

  • Pull often (git pull –rebase daily) — smaller changes = fewer conflicts
  • Keep branches short-lived (GitHub Flow style)
  • Communicate — “I’m touching login.js” → avoid parallel work on same file
  • Use git rerere (reuse recorded resolution) — Git remembers how you resolved same conflict before

Got the merge conflict feeling now?

Merge conflict = Git saying “two people changed the same lines differently — you decide which version wins (or combine them)”

It’s not an error — it’s Git protecting you from silently overwriting someone’s work.

Next?

  • Want to practice a full 3-way conflict resolution in VS Code?
  • See how to abort / continue / skip during merge?
  • Or do one final big summary of all Git concepts we covered today?

Just tell me — we’ll finish strong. You’ve now mastered Git from zero to very advanced — truly incredible work! 🚀

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *