git-branch-cleanup
Skill6 starsChanged 44 days agoMITView on GitHub
Delete local git branches whose remote tracking branch is gone or whose changes are already merged into the base branch. Use when the user asks to clean up branches, prune branches, delete stale branches, or /git-branch-cleanup. Also trigger on "tidy git branches", "remove old branches", "I'm done with these branches", "branch graveyard", or whenever the user complains about local branch clutter. Reports what will be deleted and asks before deleting anything.
We split this skill into the rules it gives an agent
7 rules. 0 are common, 1 is distinctive, and 6 are very specific to this project.
0
Common
Most of the 4 edited versions we read keep these.
1
Distinctive
This author's own choices. Worth a look.
6
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 14
If user mentioned keep-patterns inline (e.g.
- Very specific: line 29
No remote -> compare against the local <base> (git branch --merged <base>) and skip the Gone bucket entirely (no upstreams can exist)
- Very specific: line 45
Always preview + confirm. Skip prompt only if user already said "yes delete" / "go ahead" same turn - covers -d only.
- Very specific: line 46
Never delete current / base / HEAD
- Very specific: line 47
Never -D unmerged without explicit OK.
- Distinctive: line 48
Never touch remote branches.
- Very specific: line 49
Never git reflog expire / gc --prune=now.
“Common” is measured: kept by at least 6 in 10 of the 4 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Git Branch Cleanup
Prune locals = merged OR remote gone. Destructive -> preview + confirm.
Flow
- If user mentioned keep-patterns inline (e.g. "but keep
spike/*") -> capture them. Else assume none. Don't prompt up front - Parallel:
git fetch --all --prunegit branch --show-current
- Base: user names one -> use it. Else detect:
git symbolic-ref --short refs/remotes/origin/HEAD-> strip theorigin/; ref missing ->git remote set-head origin -a, re-read; no remote ->main, fall backmaster. Why -> this is a delete path, and--merged <wrong-base>misclassifies live branches as merged. Compare againstorigin/<base>, not the local ref -> the local base is often stale or absent entirely (git-branch-createbranches offorigin/<base>without ever creating it), so a local-ref check either errors or reports branches as unmerged that the remote already has - Candidates:
- Gone: upstream gone
git for-each-ref --format='%(refname:short) %(upstream:track)' refs/heads \ | awk '$2 == "[gone]" {print $1}' - Merged: fully merged into the remote base (step 1 already fetched + pruned)
git branch --merged origin/<base> --format='%(refname:short)' - No remote -> compare against the local
<base>(git branch --merged <base>) and skip the Gone bucket entirely (no upstreams can exist) - Note: squash-merged PRs leave no merge commit, so they won't appear in Merged. Closing the PR deletes the remote -> they show up in Gone instead. The Gone bucket is the catch-all for PR-merged work
- Union. Exclude:
- Current
- Base (
main/master) - Protected: exact names
develop,staging, plus any branch matching the globrelease/*. Skip silently if none exist - User keep-patterns from step 0 (if provided)
- Gone: upstream gone
- Print grouped by reason (gone vs merged), one line per branch, no prose. Ask confirm
- On confirm:
- Merged:
git branch -d <name>.-dre-checks against HEAD/upstream, notorigin/<base>, so it can refuse a branch the Merged bucket listed -> that's a safe refusal, not a bug: report it as skipped, don't reach for-D - Gone + unmerged:
git branch -D <name>. Explicit confirm only - Branch checked out in another worktree -> both
-dand-Drefuse. Same safe refusal: report as skipped, don't force it
- Merged:
- Print summary: counts + one line per skipped branch (+ why). No recap of what was already listed
Rules
- Always preview + confirm. Skip prompt only if user already said "yes delete" / "go ahead" same turn - covers
-donly;-Dof unmerged work always gets its own named-branch confirm - Never delete current / base /
HEAD - Never
-Dunmerged without explicit OK. Unsure -> list + let user decide - Never touch remote branches. Local only
- Never
git reflog expire/gc --prune=now. Deleted stay recoverable via reflog - Empty candidate list -> say so + stop
- User keep-patterns (
wip/*,spike/*) -> off-limits
Other versions5 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 5
- magnusrodseth/dotfiles★ 3same name
- fang2hou/skills★ 2same name
- juninmd/skills★ 2same name
- adacola/skills★ 1same name
- Tmeister/skills★ 1same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository21 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- blog-writeSkill
- cloudflare-hygieneSkill
- git-branch-createSkill
- git-branch-syncSkill
- git-commitSkill
- git-issue-createSkill
- git-issue-startSkill
- git-issue-triageSkill
- git-pr-createSkill
- herdr-dispatchSkill
- humanizeSkill
- macos-cleanupSkill
- macos-maintenanceSkill
- obsidian-markdownSkill
- spec-applySkill
- spec-archiveSkill
- spec-exploreSkill
- spec-proposeSkill
- spec-verifySkill
- vercel-hygieneSkill
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

