What can you do with an interactive rebase?

Git & SDLC Branching Advanced 3–5 Yrs5+ Yrs Coding 1 min read

Quick Answer

git rebase -i <base> opens a list of commits you can edit: squash/fixup to combine commits, reword to fix a message, edit to amend a commit's content, drop to remove one, and reorder lines to reorder commits. Used to tidy a messy feature branch into clean, logical commits before opening a PR.

Interactive rebase lets me rewrite my recent commits. I get a list and for each one I can squash or fixup to merge it into the previous, reword the message, edit the actual content, drop it, or reorder them. I use it to turn a branch full of “wip” and “fix typo” commits into a handful of clean, meaningful commits before I open a pull request. It rewrites history so I only do it on my own unpushed branch, or I force-push with --force-with-lease if I've shared it. And if it goes sideways, rebase --abort and the reflog have my back.

  • squash keeps both messages for you to combine; fixup discards the second message.
  • git commit --fixup=<sha> + git rebase -i --autosquash automates fold-in-fixes.
  • Only do this on unpushed / personal branches (or force-push with --force-with-lease and coordinate).
  • If a rebase goes wrong, git rebase --abort, and git reflog can recover lost commits.