agentleFS
ostin-pilostin-pil/aboard/.claude/skills/prune-branches/SKILL.md

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

  • Other versions3 projects use a version of this.

    Word for word · 0

    None found.

    Edited · 0

    None found.

    Wrote their own version · 3

    1. Pradnyeshp/Claude-Skills★ 2same name
    2. TitusKirch/skills★ 2same name
    3. 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.

  • In this repository4 other files it gives its agents.

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
  1. Very specific:

    Safe pass (batch): Run git branch -d on *all* candidates in one command.

    line 31
  2. Very specific:

    Load-bearing invariant: never -d/-D a branch absent from git branch --merged main taken on an up-to-date local main.

    line 38
  3. Distinctive:

    Never delete main or the current branch.

    line 41
  4. Distinctive:

    Always print recovery SHAs before any deletion.

    line 42

“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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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

  1. On main. git branch --show-current is main. Else abort: "switch to main first — pruning runs from main".
  2. main == origin/main. git fetch origin main then git rev-list --left-right --count origin/main...main is 0 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".
  3. Clean tree. git status --porcelain is empty. Else abort.

Abort = print the reason and stop. No deletions on a stale or dirty main.

Steps

  1. 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.
  2. Record recovery SHAs. For each candidate, git rev-parse --short <branch>. Print the name→SHA table and note: recoverable for ~90 days via git branch <name> <sha> / git reflog.
  3. Safe pass (batch). Run git branch -d on all candidates in one command. Capture which were Deleted and which were refused ("not fully merged").
  4. Reconcile refusals. Every refused branch must still be in the step-1 merged set — -d refused only because the upstream is the stale PR head, not because of unmerged work. Compute refused ∖ 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.
  5. Force pass (verified subset only). If the refused-but-merged subset is non-empty, confirm via AskUserQuestion (skip the prompt if --yes was passed). The confirm option's description must explain why it is safe — e.g. "Refused by -d only because their upstream is the stale pre-merge PR head, not because they hold unmerged work; git branch --merged main confirms they are in main; local-only; recoverable via reflog." On confirm: git branch -D <subset>. On decline: keep them, report.
  6. Report. Deleted (with SHAs), force-deleted (with SHAs), kept and why. Confirm git branch -r is unchanged — origin is never touched.

Rules

  • Load-bearing invariant: never -d/-D a branch absent from git branch --merged main taken on an up-to-date local main. 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 with git push origin --delete <branch> if ever needed.
  • Never delete main or the current branch.
  • Always print recovery SHAs before any deletion.
  • No emojis.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.