git rebase — Rewriting History
Rebase takes your commits and replays them on top of another branch tip. Unlike merge, no merge commit is created — history is rewritten to appear linear. The golden rule: never rebase commits already pushed to a shared branch.
01.Rebase vs Merge: When to Use Which
Merge preserves exact history — branch divergences and merge commits are visible. Rebase rewrites history — your commits appear to have always been on top of the latest main, creating a clean linear log. Use rebase for keeping your feature branch up-to-date with main before a PR. Use merge for integrating completed PRs to preserve the full history.
02.Interactive Rebase: The History Superpower
git rebase -i (interactive) lets you rewrite the last N commits before they are shared. Operations: pick (keep as is), squash (meld into previous commit), fixup (squash silently), reword (edit the message), reorder (drag lines), drop (delete entirely). Use this to clean up "WIP" and "fix typo" commits into professional history before opening a PR.
Commands
When should you NEVER use git rebase?