git-cleanup
Use when the user explicitly invokes branch or worktree cleanup for a repo with accumulated local branches. Don't use for remote branch deletion or force-push operations.
SKILL.mdplugins/odin-git/skills/git-cleanup/SKILL.md
GitHubGit cleanup
Contract
| Field | Bound contract |
|---|---|
| Trigger | The user explicitly invokes branch/worktree cleanup for a repository with accumulated local branches or worktrees. |
| Authority | Reversible local: writes only VCS-tracked local branches and clean worktrees; rollback is git reflog and remote refs. No remote mutation. Show the exact set before any deletion. |
| Side effect | Delete confirmed local git branches and clean worktrees only; dirty worktrees and protected branches are refused. |
| Done | Every local branch is categorized or surfaced as unanalyzed, every recommended deletion has evidence, exact quoted commands receive final confirmation, and each command is reported as deleted or failed. |
Inputs
A local git repository path (defaults to the current working directory). No remote credentials, no force-push targets, no protected-branch list beyond the repository's own configuration. The user supplies final confirmation for each deletion command; nothing is deleted without it.
Procedure
- Run
git branch -vvandgit worktree listto enumerate every local branch and worktree. Record the current branch and the default upstream branch as protected; never propose their deletion. Done when: every local branch and worktree is enumerated and the current branch plus default upstream are marked protected. - For each local branch, determine merge status against its upstream and against the current branch: run
git branch --mergedandgit branch --no-merged, thengit log <branch> --not <upstream> --onelineto surface unmerged commits. Categorize each branch asmerged,unmerged-with-evidence, orunanalyzedwhen the upstream is missing or the comparison is ambiguous. Done when: each branch carries one ofmerged,unmerged-with-evidence, orunanalyzedwith its evidence. - For each worktree, run
git -C <path> status --porcelainto classify it ascleanordirty. Mark dirty worktrees as refused for deletion. Done when: every worktree is classifiedcleanordirty. - For every branch or clean worktree recommended for deletion, attach the evidence that justifies it: the merge commit SHA, the empty
git logoutput proving no unique commits, or the worktree's clean status. Branches categorizedunanalyzedare surfaced with their reason and never recommended for deletion. Done when: each recommended deletion has its evidence attached and nounanalyzedbranch is recommended. - Present the full categorized list and, for each recommended deletion, the exact quoted command the user must confirm (for example
git branch -d <name>orgit worktree remove <path>). Do not execute any command yet. Done when: the categorized list and every recommended deletion's exact quoted command are shown, with nothing executed. - Wait for explicit human confirmation of each exact quoted command. Refuse to batch, abbreviate, or infer confirmation. Done when: the user confirms each exact quoted command individually, or declines.
- Execute only the confirmed commands, one at a time, in the order confirmed. After each command, record whether it succeeded (
deleted) or failed, capturing the exact git error message. Done when: each confirmed command ran and is recordeddeletedorfailedwith its git error message.
Failure and recovery
Dirty worktree: refuse deletion, report the uncommitted changes, and stop. The user must commit, stash, or discard changes before retrying.Protected branch: refuse deletion, name the branch, and stop. Protected branches are the current branch, the default upstream, and any branch the repository marks protected.Unanalyzed branch: surface the branch with its reason (missing upstream, ambiguous merge comparison) and never delete it. Deletion requires the user to resolve the ambiguity and re-invoke.Command failure: record the exact git error, leave all other confirmed commands pending, and report the failure. Do not retry automatically or widen scope.Missing confirmation: stop before execution. No deletion occurs. Partial results are the categorized analysis only; no branch or worktree is removed without per-command confirmation.- Recovery for an accidental deletion is
git reflogandgit branch <name> <sha>for branches, or re-adding a worktree withgit worktree add; state this recovery path when reporting any deletion.
Output
A categorized report of every local branch (merged, unmerged-with-evidence, unanalyzed, or protected) and every worktree (clean, dirty, or protected), each recommended deletion with its evidence and exact quoted command, the set of confirmed commands, and a per-command result of deleted or failed with the git error message. Branches or worktrees never confirmed remain listed as not deleted.