| name | clean-git-history |
| description | Reimplement a branch with a clean, narrative-quality git commit history suitable for reviewer comprehension. Use when asked to: rewrite git history for PR review, make commits more logical/reviewable, prepare messy work for a pull request. |
Clean Git History
Reimplement the current branch on a new branch with clean, logical commits that tell a story. The goal is for the commit history to improve a reviewer's (or future code archeologist's) understanding.
New branch name: Use the provided argument, or default to {source_branch}-clean.
Workflow
Validate source branch
- Confirm no uncommitted changes or merge conflicts
- Confirm up to date with
main
Analyze the diff
- Study all changes between source branch and
main - Understand the final intended state
- Study all changes between source branch and
Create clean branch off
mainPlan commit storyline
- Break into self-contained logical steps
- Each step should reflect a logical stage of development
Reimplement step by step
- Recreate the changes in the clean branch, committing step by step according to your plan
- Each commit should introduce a single, coherent idea, conveyed clearly in the commit message. Ideally, each commit should also pass linting, typechecking, tests; but this is definitely less important than making the history clear and understandable, and indeed sometimes it's actively better to forgo this (e.g. a standalone commit adding a failing test before a subsequent one fixing a bug). Use your judgment.
Verify correctness
- Final state must exactly match original branch
git diff {source_branch} {clean_branch}should be empty
Rules
- Never rewrite the source branch
- Omit any standard annotations that you might normally add to commit messages (e.g., "Generated with [Claude Code]", etc.), unless they are already present in the source branch commits.