git rebase

Reapply commits on top of another base commit; rewrite history.

high risk

interactive breakdown — edit the command and press Explain
$ 
⚠ Risks & cautions
Safer / dry-run alternatives
git branch backup-before-rebaseLeave a pointer to the old history so you can always reset to it.
git reflogFind the pre-rebase commit if something goes wrong.
What it does

git rebase replays commits from one branch on top of another, producing a linear history. Interactive rebase (-i) lets you squash, reorder, edit, and drop commits. Never rebase public/shared branches — it rewrites history and forces conflicts for others.

Common flags
FlagMeaning
-i --interactiveInteractive rebase: edit, squash, reorder commits
--ontoRebase onto a specific commit
--abortAbort and restore original state
--continueContinue after resolving conflicts
Examples
git rebase mainRebase current branch on top of main · explain & risk-check →
git rebase -i HEAD~5Interactively clean up last 5 commits before PR · explain & risk-check →
git rebase --abortSafely cancel a rebase in progress · explain & risk-check →
Pro tip

Use interactive rebase (`git rebase -i HEAD~N`) before raising PRs to squash fixup commits and write meaningful commit messages — keeps the project history clean and reviewable.

Related
git log git stash diff
Open the full explainer →More in Git

Reference text is hand-written and may be incomplete — check man git for your version. Test destructive commands on a non-production system first.