How to Use Interactive Rebase in Git (git rebase -i)
Interactive rebase lets you rewrite a range of commits — reordering, combining (squashing), editing, or dropping them — before they're shared.
Published September 28, 2026
git rebase -i lets you rewrite a series of commits: reorder, squash, edit, reword or drop them. It is the tool for cleaning history before a pull request.
How it works
Git opens an editor with a list of commits, each with a command (pick, reword, squash, fixup, edit, drop). Change the words, save and Git replays the commits.
It rewrites history, so use it only on commits that have not been shared.
Try it
git rebase -i HEAD~3
pick a1b2c3 Add search
squash d4e5f6 fix typo
reword 9f8e7d Add cache
Practical examples
Last three commits
git rebase -i HEAD~3Fixup commits automatically
git commit --fixup a1b2c3d
git rebase -i --autosquash mainAbort
git rebase --abortContinue after resolving conflicts
git add . && git rebase --continueCommon mistakes
- Rebasing commits already pushed and shared.
- Dropping commits accidentally (recover with reflog).
- Resolving the same conflict repeatedly.
Key takeaways
- Edit history with pick/squash/reword/drop.
- Only before sharing.
- reflog can rescue mistakes.
FAQ
pick vs fixup?
fixup squashes into the previous commit and discards its message.
How do I undo a bad rebase?
git reflog then git reset --hard HEAD@{n}.