Rebasing Deep Dive
Rebase replays your commits on top of another branch, creating a linear history.
git rebase main
Interactive rebase
git rebase -i HEAD~3 opens an editor where you can:
pick— keep the commit as-issquash/fixup— combine with previous commitreword— edit the commit messagedrop— delete the commit entirely
When to use rebase vs merge
| Scenario | Use |
|---|---|
| Integrating upstream changes locally | rebase |
| Merging a feature into main | merge (or squash merge) |
| Shared branch others are working on | Never rebase |
Golden rule
Never rebase commits that have been pushed to a shared branch. It rewrites history and forces others to reconcile diverged histories.