Git rebase interactive

LinkIconGit Rebase Interactive

git rebase -i lets you rewrite your local commit history BEFORE PUSHING.

Use it to:

  • clean up messy commits,
  • squash “wip” commits
  • edit messages.

LinkIconBasic Usage

To rewrite the last 3 commits:

# HEAD~3 means “the last 3 commits from the current branch.”
git rebase -i HEAD~3

Git will open an editor showing something like:

pick a1b2c3 commit message 1
pick d4e5f6 commit message 2
pick g7h8i9 commit message 3 (latest commit)

LinkIconCommon Commands You Can Use

"Squash third-commit into second-commit":

pick a1b2c3 first-commit
pick d4e5f6 second-commit
squash g7h8i9 third-commit

LinkIconHow To Cancel

If things go wrong:

git rebase --abort

This returns your branch to its previous state.

LinkIconConflict

If conflicts appear, resolve them, then run:

git add .
git rebase --continue