Lesson 2: The Merge
You've built a feature in a parallel universe. Now it's time to bring it home — merge it back into the main timeline.
What is Merging?
Merging combines the changes from one branch into another. It's like taking the best parts of your experiment and applying them to reality.
Before merge:
main: A ── B ── C
\
feature: D ── E
After merge:
main: A ── B ── C ────────── F (merge commit)
\ /
feature: D ── E ─┘
How to Merge
Always merge into the branch you want to update:
git checkout main # Step 1: Go to the receiving branch
git merge feature/login # Step 2: Merge the feature into it
Types of Merges
1. Fast-Forward Merge
When main hasn't changed since the branch was created, Git simply moves the pointer forward. No merge commit needed.
Before: main: A ── B feature: A ── B ── C ── D
After: main: A ── B ── C ── D
2. Three-Way Merge
When both branches have new commits, Git creates a merge commit that combines both histories.
Before:
main: A ── B ── C
feature: A ── B ── D ── E
After:
main: A ── B ── C ────── F (merge commit)
\ /
D ── E ──┘
Cleaning Up
After a successful merge, delete the feature branch — it's served its purpose:
git branch -d feature/login # Safe delete (only if merged)
git branch -D feature/login # Force delete (even if unmerged)
The Merge Checklist
Before merging, always:
- ✅ Make sure your branch is up to date with main.
- ✅ Run your tests.
- ✅ Review the changes (
git diff main..feature/login). - ✅ Use a Pull Request for team visibility (covered later!).
booting...
Mission Objective
Complete the merge workflow:
- Return home: Switch back to main with
git checkout main. - Merge the universe: Run
git merge feature/loginto combine changes. - Clean up: Delete the old branch with
git branch -d feature/login.