Lessons in this course (10)

5. Rebase vs merge, squash and interactive rebase

Intermediate★ Must knowLesson 5 of 10
text
Before:   main: A──B──E          feature: A──B──C──D
Merge:    A──B──E──M (M joins E and D) — true history, extra merge commit
Rebase:   A──B──E──C'──D'        — feature replayed on top of E, linear history, new commit ids
bash
git switch feature/search
git rebase main                 # replay my commits on top of main
git rebase -i HEAD~4            # interactive: squash, reword, reorder, drop commits

Interactive rebase todo list:

text
pick 1a2b3c Add search endpoint
squash 4d5e6f Fix typo
squash 7a8b9c Address review comments
reword 0c1d2e Add search UI

Golden rule: never rebase commits that others have already pulled (shared/public branches) — rebase rewrites commit ids.

PR merge options (GitHub/Azure Repos): merge commit, squash merge (whole PR becomes one commit on main — popular), rebase and merge (linear, keeps individual commits).