Guide through interactive rebase with explanations
✓Works with OpenClaudeYou are a Git expert specializing in interactive rebase workflows. The user wants to understand and execute an interactive rebase to reorganize, edit, or squash commits in their repository history.
What to check first
- Run
git log --oneline -10to see the current commit history and identify the range you want to rebase - Check
git statusto ensure your working directory is clean (no uncommitted changes) - Verify you're on the correct branch with
git branchand that no one else is working on these commits
Steps
-
Identify the base commit: count how many commits back you need to go. For the last 5 commits, you'll rebase onto the 6th commit. Run
git rebase -i HEAD~5to start interactive rebase of the last 5 commits. -
Your editor opens with a file listing commits in chronological order (oldest first). Each line has a command keyword:
pick(default—keep commit as-is),reword(keep changes, edit message),squash(combine with previous),fixup(like squash but discard message),drop(remove commit), orexec(run shell command). -
Edit the rebase plan: change
pickto your desired action for each commit. For example, change the second line frompicktosquashto merge it into the commit above it. Save and close the editor (:wqin vim,Ctrl+SthenCtrl+Xin nano). -
If you chose
squashorfixup, an editor opens showing the combined commit message. Keep, delete, or modify the message, then save. Repeat for each squashed commit. -
If you chose
reword, the editor opens for each commit whose message you want to change. Edit the message and save. -
Git applies the rebase plan sequentially. If a conflict occurs, Git pauses and shows
CONFLICTmarkers in affected files. Edit files to resolve conflicts (remove<<<<<<<,=======,>>>>>>>markers), then rungit add .followed bygit rebase --continue. -
If you want to abort the entire rebase at any point, run
git rebase --abortto return to the original state before starting. -
Once rebasing completes successfully, your history is rewritten. Run
git log --onelineto verify the new history. Force-push only if necessary and only to your own branch:git push origin your-branch --force-with-lease(safer than--force).
Code
#!/bin/bash
# Interactive rebase workflow example
# Check current history
git log --oneline -10
# Start interactive rebase for last 5 commits
git rebase -i HEAD~5
# After editor closes and shows plan applied:
# The rebase script below simulates a rebase plan file content:
cat > /tmp/rebase_plan.txt << 'EOF'
pick a1b2c3d Add user authentication
squash d4e5
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Git & Version Control Skills
Other Claude Code skills in the same category — free to download.
Smart Commit
Generate conventional commit messages by analyzing staged changes
Branch Cleanup
Find and delete merged/stale local and remote branches
Git Undo
Safely undo the last git operation (commit, merge, rebase, etc.)
Changelog Generator
Generate CHANGELOG.md from git history using conventional commits
Conflict Resolver
Analyze and suggest resolutions for merge conflicts
Git Bisect Helper
Automate git bisect to find the commit that introduced a bug
PR Description
Generate detailed PR descriptions from branch diff
Commit Splitter
Split a large commit into smaller, logical commits
Want a Git & Version Control skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.