Rewriting commits for a clean history — and the golden rule that keeps teams from losing work
Rebase is how teams maintain a clean, bisectable linear history instead of a tangle of merge commits. But rebasing rewrites commit SHAs — force-pushing a rebased branch that others have already pulled causes their history to diverge and creates painful conflicts. The golden rule of rebase is the most important thing to understand before using it.
Interactive rebase is one of the most powerful pre-review tools — squashing WIP commits, reordering, or rewriting messages before opening a PR is standard practice in professional teams.
Rebase takes each commit on your branch and replays it, one at a time, on top of the target commit. Because commits are immutable, this creates brand-new commit objects with new SHAs — the code changes are identical, but the parent pointers are different. The original commits still exist until garbage-collected.
Merge preserves history honestly; rebase rewrites it to look clean. Both have legitimate uses — the choice depends on whether the branch is shared.
Private branches only you have pulled are safe to rebase and force-push. Shared branches — main, develop, release — must never be rebased.
Interactive rebase turns "wip", "fix", "oops" commits into clean history before review. The reviewer sees your intent, not your process.