Clean up a branch's commit history
Plans an interactive rebase that turns a messy branch into logical, reviewable commits, with a backup, the exact todo list and a check that the code is unchanged. Use before merging a WIP branch.
Reviewers read history commit by commit, and git bisect and git revert work on commits, so each commit should be one logical change that builds on its own. Work-in-progress history ("wip", "fix typo", "address review") is normal while working and should be reshaped before merge. Interactive rebase is the tool, but it rewrites commits: the risks are losing work, breaking a shared branch, and ending with a final tree that differs from what was tested. A backup and a tree comparison remove those risks.
Plan the clean-up of this branch: Only if [TARGET_SHAPE] is given: Target shape:
- Read the log and the files each commit touches. Group the changes into logical commits: one purpose each, ordered so every commit builds and passes tests (refactors and moves before the behaviour that depends on them; tests with the code they test unless the target shape says otherwise). If the log is missing the base branch or file stats, ask for them.
- Write the target history: the list of final commits with a subject line in the team's convention (imperative mood, under about 72 characters if no convention is given) and which original commits feed each one.
- Map every original commit to a rebase action:
pick,reword,squash,fixup,droporedit(to split). Reorder lines as needed. Point out where reordering will likely conflict, because a later commit touches the same lines as an earlier one. - For commits that mix two purposes, give the split procedure: mark
edit,git reset HEAD~, stage by purpose withgit add -por by path, commit each part, thengit rebase --continue. - Mention the fixup alternative for future work:
git commit --fixup=<sha>plusgit rebase -i --autosquash. - Keep the reshape and any update to a newer base apart. Rebase onto the branch's current merge base (
git rebase -i --keep-base <base>, Git 2.24 or newer, orgit rebase -i $(git merge-base <base> HEAD)), so the final tree can be compared with the backup. Moving onto the latest base is a separate, later step. - Give the verification: the final tree must equal the backup's tree,
git range-diffshows each old commit's fate, and each commit should build and test.
- The first step is always a backup branch. Never suggest
git reset --hardorgit push --forcewithout--force-with-lease. - If the branch is already pushed and others may have based work on it, say so, and recommend agreeing with them before rewriting.
- Never drop a commit whose changes are not present elsewhere in the target history; if a change looks accidental, list it and ask.
- Use only commit hashes and messages from the log. Do not invent commits.
Target history
Numbered final commits: subject, then the original commits it absorbs.
Before you start
The backup command (git branch backup/<branch>-<date>) and a check that the working tree is clean.
Rebase todo
The git rebase -i --keep-base <base> command and the full todo list exactly as it should be edited, oldest first.
Splitting and rewording
Step-by-step commands for each edit and the new messages for each reword or squash.
Verify
git diff backup/<branch>-<date> HEAD must be empty (any difference is lost or extra work), git range-diff <base> backup/<branch>-<date> HEAD to review the mapping, and git rebase -x "<test command>" --keep-base <base> to build and test each commit.
Publish
git push --force-with-lease and when it is safe.
Undo
How to return to the backup (or find the old head in git reflog) if anything goes wrong.
1 required value still a placeholder; the assistant will ask for it.
details
- kind
- Prompt: a task you run by name to get one finished thing back
- domain
- Software engineering
- category
- Git and version control
- level
- Intermediate
- made for
- Software engineer, Open-source maintainer
- risk
- read-only
- version
- v1.0.0 · incubating
- reviewed
- 2026-10-02
- works in
- Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Antigravity, OpenCode, Windsurf, Zed, Continue, AGENTS.md, ChatGPT, claude.ai
use in
npx @hermes-hq/hodios install clean-up-commit-history --target claude-codenpx skills add hermes-hq/hodios-dist --skill clean-up-commit-history -a claude-codeclaude plugin marketplace add hermes-hq/hodios-distclaude plugin install hodios-software-engineering@hodiosThe plugin brings every entry in this domain at once.
more in git and version control
All of Git and version controlRecover lost Git work
Recovers commits, branches, stashes and staged files lost to a reset, rebase or dropped stash, using reflog and fsck after a backup, explaining each command. Use right after a git mistake.
recover-lost-git-workResolve a merge conflict
Resolves merge, rebase or cherry-pick conflicts by reading both sides and their common base, keeps the intent of each, and asks when the intents contradict. Use when git stops on a conflict.
resolve-merge-conflictWrite a commit message
Writes a commit message that states what changed and why, in the repo's own convention, and flags staged changes that should be split. Use before committing.
write-commit-messageWrite a pull request description
Writes a pull request description that tells reviewers why the change exists, what to look at first, how to test it and what could break. Use when opening a PR.
write-pr-descriptionChoose a branching strategy
Recommends a branching and release strategy such as trunk-based, GitHub flow or release branches for a team's size, cadence and environments, with rules, protections and migration steps.
choose-branching-strategyConventional Commits rules
Makes the assistant write every commit in Conventional Commits 1.0.0 format, one logical change per commit, with honest breaking-change footers. Use in repos that release from commits.
conventional-commits-rules