Reapply commits on top of another base commit; rewrite history.
high risk
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.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.
| Flag | Meaning |
|---|---|
-i --interactive | Interactive rebase: edit, squash, reorder commits |
--onto | Rebase onto a specific commit |
--abort | Abort and restore original state |
--continue | Continue after resolving conflicts |
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 →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.
Reference text is hand-written and may be incomplete — check man git for your version. Test destructive commands on a non-production system first.