Interactive Rebase
You'll learn how to rewrite commit history using interactive rebase to clean up, reorganize, or edit past commits before sharing them.
What Is Interactive Rebase?
Interactive rebase is Git's powerful tool for rewriting commit history. While a normal merge or rebase simply applies commits, interactive rebase lets you pause and modify each commit—squashing multiple commits into one, reordering them, editing their messages or content, or even deleting commits entirely.
Think of it like editing a rough draft before publishing: you can combine paragraphs, rearrange sections, or delete redundant sentences to create a cleaner final version.
How It Works
When you run git rebase -i <base-commit>, Git opens an editor showing a list of commits from your current branch back to the specified base. Each line starts with an action keyword:
- pick – keep the commit as-is
- reword – keep changes but edit the commit message
- edit – pause to modify the commit's content
- squash – combine this commit with the previous one
- fixup – like squash, but discard this commit's message
- drop – remove the commit entirely
You can also reorder commits by rearranging lines.
After saving the editor, Git executes your instructions step-by-step, stopping whenever you chose "edit" so you can make changes.
When to Use It
Interactive rebase shines when preparing a feature branch for merging. You can squash "WIP" or "fix typo" commits into meaningful units, reorder commits logically, or split one large commit into smaller pieces. This creates a cleaner, more understandable history for code review and future reference.
Key Takeaway: Interactive rebase lets you sculpt commit history into a clear, logical narrative by squashing, reordering, editing, or dropping commits before sharing your work.