Resolve Git Merge Conflicts with Confidence
You will deliberately create a merge conflict, read the conflict markers, and resolve it correctly. By the end conflicts will feel routine rather than scary, and you will know how to back out safely.
Learning Objectives
- Understand why and when conflicts occur.
- Read and resolve conflict markers.
- Verify the merge and abort safely if needed.
- Time: ~2 hours · Difficulty: Intermediate · Prereqs: the Git fundamentals lab.
Architecture Overview
graph LR
Base[common ancestor] --> A[branch A edits line 5]
Base --> B[branch B edits line 5]
A --> M{merge}
B --> M
M -->|same lines| Cf[Conflict to resolve]
Environment Setup
You will need: Git and an optional merge tool (VS Code, meld).
Before you begin: conflicts happen when two branches change the same lines; that is normal.
Step-by-Step Execution
01
Trigger a conflict
git merge feature/apiIf both branches changed the same lines, Git pauses with a conflict.
02
Read the conflict markers
<<<<<<< HEAD
const port = 8080; // your change
=======
const port = 3000; // their change
>>>>>>> feature/api
03
Resolve and complete the merge
$ git add config.js && git commit --no-edit
[main 7f3a] Merge branch 'feature/api'
Progress So Far
graph LR
A[01 Trigger] -->|done| B[02 Read markers]
B -->|done| C[03 Resolve + commit]
style A fill:#1a4a1a,stroke:#00ff00,color:#fff
style B fill:#1a4a1a,stroke:#00ff00,color:#fff
style C fill:#1a4a1a,stroke:#00ff00,color:#fff
Testing & Validation
git status && git diff --checkStatus should show a clean tree and diff --check should report no remaining conflict markers. Run your tests to confirm the merge is correct, not just conflict-free.
Troubleshooting
- Leftover markers committed:
git diff --checkcatches<<<<markers before commit. - Resolved the wrong way: the merge is just a commit; revert and redo.
- Overwhelmed: back out cleanly with
git merge --abortand try again.
Extension Ideas
- Configure a visual mergetool for big conflicts.
- Reduce conflicts by keeping branches short (see Branching).
- Catch issues earlier with CI in GitHub Actions.
Key Results
- Resolved a real conflict by reading the markers.
- Confirmed zero leftover markers with
diff --check. - Validated correctness with tests, not just a clean status.
- Learned to abort and retry without panic.