prune-branches
Skill2 starsChanged 3 months agoApache-2.0View on GitHub
Delete local branches already merged into main, gated on `git branch --merged main`
- Commits and pushes
3 other projects use a version of this.
Adopted by
Most recently taken up by
- TitusKirch/skillstheir own version, first seen Oct 13, 2026
- wardawgmalvicious/agent-configtheir own version, first seen Oct 13, 2026
- Pradnyeshp/Claude-Skillstheir own version, first seen Jul 6, 2026
Other versions3 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 3
- Pradnyeshp/Claude-Skills★ 2same name
- TitusKirch/skills★ 2same name
- wardawgmalvicious/agent-config★ 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.
The file
We split this skill into the rules it gives an agent
4 rules. 0 are common, 2 are distinctive, and 2 are very specific to this project.
0
Common
Most of the 3 edited versions we read keep these.
2
Distinctive
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 31
Safe pass (batch): Run git branch -d on *all* candidates in one command.
- Very specific: line 38
Load-bearing invariant: never -d/-D a branch absent from git branch --merged main taken on an up-to-date local main.
- Distinctive: line 41
Never delete main or the current branch.
- Distinctive: line 42
Always print recovery SHAs before any deletion.
“Common” is measured: kept by at least 6 in 10 of the 3 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
Post-merge hygiene. This repo's workflow (work on feature/session-N-* / track-* branches → PR from the ostin-pil fork → merge commit on GitHub → pull main) leaves stale local branches every cycle. They clog git branch and produce confusing git status "ahead N" lines because they still track the now-merged PR head.
The non-obvious trap this skill exists to encode: git branch -d will refuse a fully-merged branch ("not fully merged") when that branch's upstream is the stale/merged PR head — even though the branch is merged into main (HEAD). git branch --merged main is the truth; for branches it lists, -D is safe even when -d balks.
Argument
$ARGUMENTS — optional --yes to skip the force-delete confirmation (non-interactive use). Anything else is ignored.
Preconditions — all must hold; abort (delete nothing) otherwise
- On
main.git branch --show-currentismain. Else abort: "switch to main first — pruning runs from main". main==origin/main.git fetch origin mainthengit rev-list --left-right --count origin/main...mainis0 0.- Behind → abort: "local main is behind origin/main; pull first — 'merged into main' would be measured against a stale main".
- Ahead → abort: "local main has unpushed commits; resolve first".
- Clean tree.
git status --porcelainis empty. Else abort.
Abort = print the reason and stop. No deletions on a stale or dirty main.
Steps
- Compute the merged set (source of truth).
git branch --merged main | grep -vE '^\*| main$'(trim whitespace). This is the only set eligible for deletion. Empty → print "no merged local branches to prune" and stop. - Record recovery SHAs. For each candidate,
git rev-parse --short <branch>. Print the name→SHA table and note: recoverable for ~90 days viagit branch <name> <sha>/git reflog. - Safe pass (batch). Run
git branch -don all candidates in one command. Capture which wereDeletedand which were refused ("not fully merged"). - Reconcile refusals. Every refused branch must still be in the step-1 merged set —
-drefused only because the upstream is the stale PR head, not because of unmerged work. Computerefused ∖ merged-set: it must be empty. If any refused branch is not in the merged set, that is an anomaly — do not delete it; report it and keep it. - Force pass (verified subset only). If the refused-but-merged subset is non-empty, confirm via
AskUserQuestion(skip the prompt if--yeswas passed). The confirm option's description must explain why it is safe — e.g. "Refused by-donly because their upstream is the stale pre-merge PR head, not because they hold unmerged work;git branch --merged mainconfirms they are in main; local-only; recoverable via reflog." On confirm:git branch -D <subset>. On decline: keep them, report. - Report. Deleted (with SHAs), force-deleted (with SHAs), kept and why. Confirm
git branch -ris unchanged — origin is never touched.
Rules
- Load-bearing invariant: never
-d/-Da branch absent fromgit branch --merged maintaken on an up-to-date localmain. That single fact is the only thing that makes force-delete safe. - Preconditions are hard gates, not warnings. "Merged into main" is meaningless against a stale or dirty
main— abort, delete nothing. - Local-only. Never delete, prune, or push branches on
origin. Remote pruning is deliberately out of scope; do it by hand withgit push origin --delete <branch>if ever needed. - Never delete
mainor the current branch. - Always print recovery SHAs before any deletion.
- No emojis.
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.

