Git — Resolving Merge Conflicts

Step-by-step process for resolving merge conflicts when two branches edit the same file.

Why / When to Use

Conflicts occur when two branches modify the same line(s) and Git cannot auto-merge. You must manually pick the correct version.

Core Concept / Commands

Scenario

Two developers both edited timeout in config.ts. Teammate merged first. Now your PR has a conflict.

Step-by-step resolution

1. Pull latest main into your branch

git checkout main
git pull origin main
 
git checkout feat/your-branch
git merge main
# Git reports: CONFLICT (content): Merge conflict in config.ts

2. Open the conflicted file — you’ll see conflict markers

<<<<<<< HEAD
const timeout = 5000        ← your version
=======
const timeout = 1000        ← their version
>>>>>>> main
const retries = 2           ← no conflict here

3. Resolve by choosing the correct version, delete ALL markers

const timeout = 5000    // kept yours after agreeing with teammate
const retries = 2
const apiUrl = "https://api.example.com"

Delete all 4 marker lines: <<<<<<< HEAD, =======, >>>>>>> main, and the unwanted version.

4. Verify no markers remain

grep -n "<<<<<<" config.ts   # should return nothing

5. Stage and commit

git add config.ts
git commit -m "fix: resolve merge conflict in timeout config"
git push origin feat/your-branch

6. PR now shows green

✅ This branch has no conflicts with the base branch

Key Options / Variants

VS Code conflict UI (easier)

VS Code highlights conflicts with coloured blocks and shows 3 clickable buttons:

  • Accept Current Change — keep your version (green)
  • Accept Incoming Change — keep theirs (blue)
  • Accept Both Changes — keep both lines

No manual marker deletion needed.

Gotchas

  • A leftover conflict marker (<<<<<<<) in committed code = broken build/compile error
  • Always search for <<<< across the entire file before staging
  • For complex conflicts, talk to your teammate before resolving so you pick the right version

The Golden Rules

RuleWhy
Pull main into your branch regularlySmaller, less painful conflicts
Never leave conflict markers in codeApp will break
Talk to teammate before touching same filePrevent it entirely
One small PR at a timeLess overlap with others

Source

Conversation: “Merging PR with complete test coverage” — 2026-05-18