By admin , 29 April 2026

Synopsis

git rebase -i <upstream>
git rebase -i --root

Description

Interactive rebase opens an editor with the list of commits to be rebased, each prefixed with an action: pick, reword, edit, squash, fixup, drop, exec, or break. By editing this list, you can reorder, combine, split, or remove commits before they go upstream. It's the workhorse of "clean up history before pushing."

Combined with --autosquash, fixup commits created via git commit --fixup are automatically arranged next to their targets and marked for squashing. The --rebase-merges flag preserves merge commits during interactive rebase.

In day-to-day use, git rebase -i integrates closely with shell aliases, editor plugins, and continuous integration. Power users often add aliases that combine flags they always pass, or wrap the command in scripts that enforce team conventions. Output formatting can be customized via Git config — pretty formats, color schemes, and pager behavior are all tunable. When something goes wrong, the first diagnostic step is usually to re-run the command with GIT_TRACE=1 in the environment, which reveals the underlying plumbing calls. For unusual situations, the --help output (git rebase -i --help) opens the full manual page with details on every option, including those rarely used in casual workflows but essential for debugging or scripting at scale.

Understanding how git rebase -i interacts with the rest of Git's data model — the object database, the index, refs, and the working tree — pays dividends. Each command operates on some subset of these pieces, and knowing which it touches helps predict outcomes and recover from mistakes. Reading the official Git documentation alongside hands-on practice in a throwaway repository is the fastest way to internalize the nuances. Most production issues with Git stem from one of three causes: surprising default behavior, partial network operations, or rewriting history that was already shared. A working mental model of git rebase -i's side effects helps avoid all three.

Common Options

OptionDescription
-iInteractive editor for rebase plan.
--autosquashAuto-arrange fixup/squash commits.
--rootRebase from the very first commit.
-x <cmd>Run a command between commits (e.g. tests).
-r, --rebase-mergesPreserve merge commits.
--continueResume after resolving.
--abortCancel completely.

Examples

git rebase -i HEAD~5
# Edit the last 5 commits

git commit --fixup abc123
git rebase -i --autosquash abc123^
# Add a fixup, then auto-squash on rebase

git rebase -i -x "npm test" main
# Run tests after each commit during rebase

git rebase -i --root
# Rewrite history from the first commit

Common Mistakes

Saving an empty rebase todo list aborts the operation — leave at least one pick line. Marking too many commits as edit creates a tedious sequence of stops; prefer squash or fixup when you just want to combine. Never interactive-rebase commits that are already pushed and shared.

Related Commands

git rebase, git commit --fixup, git cherry-pick, git reflog