Skip to content

skillGit and releases

Git History Cleanup

Turns a noisy branch of wip and fixup commits into a short, logical series with interactive rebase, with a backup and a tree-equality check.

npx workspacetemplates add git-history-cleanup --tool claude-code

Writes 1 file to .claude/skills/git-history-cleanup/

.claude/skills/git-history-cleanup/SKILL.md27 lines · 1.8 KBFile
---
name: git-history-cleanup
description: Turns a noisy branch of wip and fixup commits into a short, logical series with interactive rebase, with a backup and a tree-equality check.
---

# Git history cleanup

Rewrite only unpublished history, and prove the end result is identical.

## Steps

1. Check what you are about to rewrite: `git status` must be clean, and `git log origin/<branch>..HEAD` shows the unpushed commits. If the branch is already pushed and others may have it, stop and ask first.
2. Make a backup: `git branch backup/<branch>-before-cleanup`. Record the tree: `git rev-parse HEAD^{tree}`.
3. Read the whole range with `git log --stat --reverse <base>..HEAD` and design the target series on paper: usually 3 to 7 commits, ordered so each one builds (refactor, then behavior, then tests, then docs).
4. Rebase without an editor prompt. Write the rebase plan yourself and pass it with `GIT_SEQUENCE_EDITOR` (for example a small script, or `git commit --fixup` followed by `git rebase -i --autosquash <base>`). Use `reword` for messages, `fixup` to fold, `edit` to split a commit with `git reset HEAD^` and staged hunks.
5. Messages: imperative subject under 72 characters, a blank line, then why the change was made. No "wip", no ticket-only subjects.
6. After every `edit` stop, run the build and the fast tests so each commit stands.
7. Verify: `git rev-parse HEAD^{tree}` must equal the recorded tree. If it differs, the rewrite changed code: reset to the backup and retry.

## Rules

- Never rewrite `main` or any shared branch. Never force-push; tell the user to use `git push --force-with-lease` themselves.
- If the rebase conflicts, resolve carefully or abort with `git rebase --abort`.

## Report

Old and new commit lists, and confirmation that the trees match.

What it does

A branch with forty commits named "fix", "fix 2" and "oops" is hard to review and hard to bisect. This skill rewrites it into a handful of commits that each tell one thing, without changing what the branch finally does.

Safety comes first: a backup branch is created, the final tree is compared byte for byte with the original, and nothing already shared is rewritten unless you say so.

Example

you › Clean up my branch before I open the pull request

agent › Rewrote 23 commits into 5: extract PriceCalculator, add currency rounding, wire checkout, tests, changelog. Every commit builds. Tree hash matches the backup (backup/cart-before-cleanup). Not pushed; use `git push --force-with-lease` when ready.

Questions

What if something goes wrong halfway?
Your original commits sit on the backup branch, and git rebase --abort returns you to the start. Nothing is lost.
Can it clean up a branch my teammates use?
It stops and asks. Rewriting shared history forces everyone else to repair their copies, so that choice stays with you.
  • Git Bisect Regression

    SkillGit and releases

    Free
  • Git Conflict Resolution

    SkillGit and releases

    Free
  • Monorepo Management

    Skilltypescript

    Free
  • Release Checklist

    SkillGit and releases

    Free