Interactive Rebase

Rewrite your local history by squashing, dropping, and rewording commits before sharing them.

Version Control7 min readConcept 23 of 29

The git rebase -i command

git rebase -i (or --interactive) begins an interactive rebasing session.

Instead of blindly moving a sequence of commits to a new base, it opens an editor allowing you to alter individual commits. It lets developers rewrite local history by removing, splitting, reordering, or combining an existing series of commits before they are finalized.

Why it matters

Web developers often make dozens of small, messy 'WIP' commits while building a feature (e.g., 'fix typo', 'try again').

Before merging the feature branch into main, git rebase -i allows you to rewrite this history. You can squash tiny commits into a single cohesive feature commit, ensuring the project's public history remains clean, linear, and easy to review.

How it works

When you run git rebase -i <base_commit>, Git opens your default text editor with a script of your commits listed in chronological order.

Each line starts with a command word (defaulting to pick). You edit this file by changing the commands (e.g., squash to meld a commit into the previous one, drop to delete it) and save the file.

Once saved, Git automatically executes the script top-to-bottom, applying the specified actions step-by-step.

Check yourself

Pick an answer to lock it in, then read why. Getting one wrong is part of how it sticks.

  1. 1What is the primary purpose of using `git rebase -i`?
  2. 2What happens if you change the command word from `pick` to `squash` in the interactive rebase editor?
  3. 3What is the golden rule of rebasing, especially interactive rebasing?

Remember this

  • Interactive rebase lets you rewrite local history using a text editor.
  • Change 'pick' to 'squash' to combine commits.
  • Change 'pick' to 'drop' to delete a commit entirely.
  • Never interactively rebase commits that have been pushed to a shared remote.

Done with this concept?

Mark it complete to track your progress. No login needed.