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

Interactive rebase lets you rewrite a range of commits — reordering, combining (squashing), editing, or dropping them — before they're shared.

Key points

  • git rebase -i HEAD~5 opens the last 5 commits in an editor where each can be marked pick, squash, edit, or drop
  • Commonly used to clean up a messy feature branch into a small number of logical commits before opening a pull request
  • Never interactively rebase commits that have already been pushed and pulled by someone else — it rewrites history

Example

git rebase -i HEAD~5
More Git articles