Summary: Merge conflicts
The one-sentence definition
Section titled “The one-sentence definition”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.”
The six-step resolution
Section titled “The six-step resolution”- Recognize:
git statusshows “Unmerged paths” - Find: open each conflicting file; locate
<<<<<<<markers - Decide: choose your version, their version, both combined, or new
- Edit: write the resolution; delete all marker lines
- Stage:
git add <file> - Commit:
git commit
Enable diff3 (one-time setup)
Section titled “Enable diff3 (one-time setup)”git config --global merge.conflictstyle diff3# or the modern alternative:git config --global merge.conflictstyle zdiff3Shows the common ancestor in conflict markers. Strictly better than the default.
The five conflict types
Section titled “The five conflict types”| Type | What it looks like | Fix |
|---|---|---|
| Textual | <<<<<<< markers in the file | Read both sides; pick one or combine; remove markers |
| Logical combine | Markers around adjacent changes | Combine both changes; write a test for the combined behavior |
| Semantic | NO markers; auto-merge succeeded | Integration 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-edit | Two paths with overlapping content | Apply edits to the new path; git rm the old path |
When to abort
Section titled “When to abort”git merge --abortWhen: 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)”- Rebase often: small daily conflicts beat one massive one later
- Small PRs: short-lived branches diverge less
- Communicate big refactors: five minutes prevents days
- Avoid long-lived branches: feature flags + small PRs beat 3-week branches
- Clear ownership boundaries: two engineers on different modules conflict less
Stay-calm psychology
Section titled “Stay-calm psychology”- Nothing is destroyed. Both branches’ work is safe.
- The merge can be undone with
git merge --abort. - The mechanics are mechanical. Six steps.
What you carry into L8
Section titled “What you carry into L8”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).
Voice anchor
Section titled “Voice anchor”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.