Git-hex Branch Cleanup
Use this skill when the user wants to reshape a feature branch's commit history using git-hex tools instead of manual interactive rebase.
Workflow
1. Assess the situation
- Call
git-hex-getRebasePlanto see the commit range.- Use
countto control how far back (default 10, max 200). - Commits come back oldest-first — the natural order for a rebase plan.
- If
ontois omitted it defaults to@{upstream}orHEAD~count.
- Use
- Optionally call
git-hex-checkRebaseConflictsto predict conflicts before starting. This requires git 2.38+ — if the user's git is older, skip it and note the limitation.
2. Choose the right tool for the job
| Goal | Tool | Notes |
|------|------|-------|
| Edit the last commit (message or content) | amendLastCommit | Use addAll: true to stage tracked changes automatically. Needs at least staged changes OR a new message. |
| Fix an older commit | createFixup → rebaseWithPlan | User must stage changes first. Then createFixup targets the commit; follow with rebaseWithPlan using autosquash: true to fold it in. |
| Reorder, drop, squash, or reword | rebaseWithPlan | Pass a plan array. For reordering, set requireComplete: true. |
| Break a commit into focused pieces | splitCommit | Requires splits array with ≥2 entries. Every file in the original commit must appear in exactly one split. |
| Cherry-pick a single commit | cherryPickSingle | Rejects merge commits. Use abortOnConflict: false to pause on conflicts instead of aborting. |
3. Execute safely
- Prefer
autoStash: truewhen the working tree is dirty.rebaseWithPlanuses git's native--autostash.amendLastCommituses--keep-indexmode (preserves staged changes).splitCommitandcherryPickSingleuse git-hex's own stash helper.
- Never rewrite shared or protected branches — only feature branches the user controls.
- All write operations create backup refs automatically.
4. Handle stash restore failures
Tools that manage their own stash (amendLastCommit, splitCommit,
cherryPickSingle) return stashNotRestored: true if the stash pop fails
after the operation succeeds. When you see this:
- Tell the user their operation succeeded but their stashed changes couldn't be reapplied cleanly.
- Suggest running
git stash listto find the stash entry, thengit stash popmanually to resolve any conflicts.
rebaseWithPlan uses git's native --autostash and does not emit this flag —
git handles it internally.
5. Recover from mistakes
- Call
git-hex-undoLastto restore the state before the last git-hex operation. - It requires a clean working tree. Use
force: trueonly if commits were added after the backup or untracked files would be overwritten. - If a rebase pauses with conflicts, hand off to the git-hex-conflict-resolution skill.
Gotchas
rewordrequiresmessage— without it, git opens an editor and hangs.- Messages must be single-line — no TAB or newline characters in
messagefields forreword,splitCommit, orcreateFixup. createFixupneeds staged changes — it doesn't stage anything itself. Remind the user togit addfirst.requireComplete: true— when reordering, every commit in the range must appear in the plan. Without this, unmentioned commits default topick.- Prefer
fixupoversquashunless the user wants to combine commit messages (squash opens an editor-like message merge; fixup silently discards). - Root commits can't be split —
splitCommitrejects them. - Merge commits can't be split or cherry-picked — both tools reject them.
- Detached HEAD —
getRebasePlanandrebaseWithPlanwarn about this in their summary. Flag it to the user if unexpected.