Skip to content

Summary: Merge conflicts

A merge conflict is git asking you a question: “two branches changed these same lines in different ways; please tell me which version you want.”

  1. Recognize: git status shows “Unmerged paths”
  2. Find: open each conflicting file; locate <<<<<<< markers
  3. Decide: choose your version, their version, both combined, or new
  4. Edit: write the resolution; delete all marker lines
  5. Stage: git add <file>
  6. Commit: git commit
Terminal window
git config --global merge.conflictstyle diff3
# or the modern alternative:
git config --global merge.conflictstyle zdiff3

Shows the common ancestor in conflict markers. Strictly better than the default.

TypeWhat it looks likeFix
Textual<<<<<<< markers in the fileRead both sides; pick one or combine; remove markers
Logical combineMarkers around adjacent changesCombine both changes; write a test for the combined behavior
SemanticNO markers; auto-merge succeededIntegration tests catch it; review with the merged result in mind
Delete-modify”deleted by us / modified by them”git rm (delete wins) or git add (modify wins)
Rename-editTwo paths with overlapping contentApply edits to the new path; git rm the old path
Terminal window
git merge --abort

When: conflicts too large to resolve calmly, wrong branch checked out, teammate’s branch has unexpected commits, you’re tired. Abort is not failure; it’s taking a do-over.

Conflict prevention (in order of leverage)

Section titled “Conflict prevention (in order of leverage)”
  1. Rebase often: small daily conflicts beat one massive one later
  2. Small PRs: short-lived branches diverge less
  3. Communicate big refactors: five minutes prevents days
  4. Avoid long-lived branches: feature flags + small PRs beat 3-week branches
  5. Clear ownership boundaries: two engineers on different modules conflict less
  • Nothing is destroyed. Both branches’ work is safe.
  • The merge can be undone with git merge --abort.
  • The mechanics are mechanical. Six steps.

You can resolve any conflict you’ll hit in two-person collaboration. L8 covers the final Phase 2 topic: how branches travel across repositories (remotes, forks, push, fetch, pull).

Git stores snapshots. Every other command is just navigating those snapshots.

A conflict is git asking which snapshot to make current. The resolution is your answer.