Cleanup
Delete stale local git branches — ones whose remote was deleted after a merged or squashed PR (upstream "[gone]"), ones already merged into the default branch — and prune stale remote-tracking refs. Use when the user asks to clean up branches, remove old/dead/merged branches, "prune gone branches", tidy up their local repo, or says their branch list is a mess. Always previews and asks before deleting; never touches the current or default branch. Invoke with /cleanup.From its SKILL.md
npx -y skills add Darmikon/skills --skill cleanupAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
SKILL.md
5.1 KB, as published. Nobody here has run it
Git Cleanup (prune stale local branches)
Remove local branches that have outlived their purpose. Two things pile up:
- Gone branches — you opened a PR, it got merged (often squash-merged), the remote branch was deleted, but your local copy lingers. Git marks its upstream
[gone]. Squash-merges are the common case and matter because they do not show up as "merged" to git — the squashed commit has a different hash — so--mergedalone misses them. - Merged branches — branches whose commits are already in the default branch by normal (non-squash) merge.
Deleting branches is destructive, so this skill previews everything and waits for confirmation, and it will never delete the branch you're on or the default branch.
Workflow
Step 1: Prune remotes first
--prune drops remote-tracking refs (origin/old-thing) whose branches were deleted upstream — that's what makes local branches show as [gone].
git fetch --all --prune
Step 2: Identify the branches to protect
CURRENT=$(git rev-parse --abbrev-ref HEAD)
DEFAULT=$(git symbolic-ref --quiet --short refs/remotes/origin/HEAD 2>/dev/null | sed 's@^origin/@@')
if [ -z "$DEFAULT" ]; then # probe locally — `git remote show origin` would stall on an unreachable remote
for c in main master; do
git rev-parse --verify --quiet "origin/$c" >/dev/null && { DEFAULT=$c; break; }
git rev-parse --verify --quiet "$c" >/dev/null && { DEFAULT=$c; break; }
done
fi
[ -z "$DEFAULT" ] && DEFAULT=main
# Ref to test "merged into default" against — fresh remote default if present, else local, else none.
# (Without this, a no-origin repo hits `fatal: malformed object name origin/main`.)
git rev-parse --verify --quiet "origin/$DEFAULT" >/dev/null && BASE="origin/$DEFAULT" \
|| { git rev-parse --verify --quiet "$DEFAULT" >/dev/null && BASE="$DEFAULT" || BASE=""; }
The current branch, the default branch, and master/main are never candidates — exclude them from every list below.
Step 3: Find gone branches (upstream deleted)
git for-each-ref --format='%(refname:short) %(upstream:track)' refs/heads \
| awk '$2=="[gone]"{print $1}' \
| grep -vFx -e "$CURRENT" -e "$DEFAULT" -e "main" -e "master"
For each, note whether git also considers it merged — this decides safe vs. force delete later:
# merged into default? (safe) — otherwise it was squash-merged and needs a force delete
[ -n "$BASE" ] && git branch --merged "$BASE" --format='%(refname:short)' # "safe" list (skipped if no default ref)
Step 4: Find merged branches (not necessarily gone)
[ -n "$BASE" ] && git branch --merged "$BASE" --format='%(refname:short)' \
| grep -vFx -e "$CURRENT" -e "$DEFAULT" -e "main" -e "master"
Step 5: Preview, grouped and honest about risk
Present two groups, de-duplicated. For each branch show why it's a candidate. Example:
Safe to delete (merged into main):
chore/bump-deps
docs/readme-tidy
Gone from remote — not merged into main (squash-merged, OR a PR closed unmerged; needs force delete -D):
feature/checkout-redesign ⚠ verify this really landed in the PR before deleting
bugfix/null-price-crash ⚠
Anything that is [gone] but not merged is the only real risk: if the PR wasn't actually merged (closed without merging, or you're mid-work), a -D throws the commits away. Call these out individually and make the user confirm them explicitly — don't bundle them into a blanket "delete all".
Step 6: Delete, after confirmation
- Merged / safe branches —
-drefuses if git disagrees, so it's self-protecting:git branch -d <branch> - Gone-but-squash-merged branches — require
-D(force). Only after the user confirms these specific branches:git branch -D <branch>
Never pipe the whole list into -D blindly. Delete the safe ones freely; force-delete only what the user OK'd by name.
Step 7: Report
List what was deleted and what was kept (and why anything was skipped — e.g. "kept feature/x: gone from remote but has unmerged commits, wasn't confirmed").
Example
User: /cleanup
Assistant: Pruned remotes. Found:
Safe (merged into main): chore/bump-deps, docs/readme-tidy
Gone/squash-merged (need force delete): feature/checkout-redesign
I'll delete the two safe ones. For feature/checkout-redesign — its PR looks squash-merged,
but force-delete drops its 3 local commits. Confirm that one?
User: yes all
Assistant: Deleted chore/bump-deps, docs/readme-tidy (-d), feature/checkout-redesign (-D). Kept main and your current branch.