All chapters in this track
- 011. The Mental Model
- 022. Essential Setup
- 033. Core Daily Workflow
- 044. Branching
- 055. Merging & Conflict Resolution
- 066. Rebasing
- 077. Remote Repositories
- 088. Stashing
- 099. Undoing Things
- 1010. Tagging & Versioning
- 1111. Cherry-Pick
- 1212. Git Bisect & Blame
- 1313. Git Hooks
- 1414. Submodules
- 1515. Team Workflows
- 1616. Power Commands & Aliases
- 1717. Reflog: The Safety Net
- 1818. Practice Tasks
- 19Quick Reference Cheatsheet
Chapter 5 of 19
5. Merging & Conflict Resolution
Fast-forward merge (no divergence)
git switch main
git merge feature/login # if main hasn't moved, HEAD just advances
3-way merge (branches diverged)
git merge feature/login # creates a merge commit
git merge --no-ff feature/login # always create merge commit (preserves history)
git merge --squash feature/login # squash all branch commits into one staged change
Resolving conflicts
When Git can't auto-merge, you see conflict markers:
<<<<<<< HEAD
return user.isAdmin;
=======
return user.role === 'admin';
>>>>>>> feature/role-check
Steps to resolve:
# 1. See which files conflict
git status
# 2. Edit each conflicted file — remove markers, keep the right code
# 3. Mark resolved
git add path/to/file.txt
# 4. Complete the merge
git commit
# OR abort entirely
git merge --abort
Merge tool:
git mergetool # opens configured visual diff tool
git config --global merge.tool vscode
Merge vs Rebase — when to use each
| Situation | Prefer |
|---|---|
| Shared/public branch | Merge (preserves history) |
| Local cleanup before PR | Rebase (linear history) |
| Main ← feature | Merge |
| feature ← updated main | Rebase (keep feature up-to-date) |