CLSkills
Git & Version Controladvanced

Interactive Rebase

Share

Guide through interactive rebase with explanations

Interactive Rebase

Guide through interactive rebase with explanations

Guide through interactive rebase to clean up commit history.

Instructions

  1. Start interactive rebase for the last N commits:
git rebase -i HEAD~5       # last 5 commits
# or
git rebase -i main         # all commits since branching from main
  1. Explain rebase actions:
pick   — keep the commit as-is
reword — keep the commit but change its message
edit   — stop and let you amend the commit
squash — combine with previous commit, merge messages
fixup  — combine with previous commit, discard this message
drop   — remove the commit entirely
  1. Common rebase recipes:

Squash all branch commits into one: Change all but first pick to squash (or fixup)

Reorder commits: Just move lines up/down in the editor

Split a commit: Change to edit, then:

git reset HEAD~1
git add file1 && git commit -m "part 1"
git add file2 && git commit -m "part 2"
git rebase --continue
  1. If things go wrong:
git rebase --abort    # cancel and go back to original state

Rules

  • Never rebase commits that are already pushed to a shared branch
  • If rebasing a pushed branch, you'll need git push --force-with-lease (safer than --force)

Quick Info

Difficultyadvanced
Version1.0.0
AuthorClaude Skills Hub
gitrebasehistory

Install command:

curl -o ~/.claude/skills/interactive-rebase.md https://claude-skills-hub.vercel.app/skills/git/interactive-rebase.md