dev10x:git-branch-prune
/dev10x:git-branch-prune
Classify and prune stale local branches with merge verification, designed for rebase-merge repos where `git branch --merged` misses most merged branches. TRIGGER when: local repo has accumulated stale branches after fanout sessions, worktree cleanup, or manual sweeps. DO NOT TRIGGER when: working on a clean repo with few branches or when branch deletion is handled by another skill (e.g. dev10x:fanout teardown).
- Author
- dev10x-guru ↗
- Repository
- dev10x-claude ↗
- Licence
- MIT
- Last repository change
- 12.10.2026
Assessment and security
- Files in this package
- 2
- Scripts
- 0
- HTML comments
- 0
- URLs in SKILL.md
- 0
No signals detected. Repository changed on 12.10.2026, without references to retired models or APIs.
MIT, open: use and modify while retaining author attribution.
What it does and when to use it
Classify and prune stale local branches with merge verification, designed for rebase-merge repos where `git branch --merged` misses most merged branches. TRIGGER when: local repo has accumulated stale branches after fanout sessions, worktree cleanup, or manual sweeps. DO NOT TRIGGER when: working on a clean repo with few branches or when branch deletion is handled by another skill (e.g. dev10x:fanout teardown).
Original author description
Classify and prune stale local branches with merge verification, designed for rebase-merge repos where `git branch --merged` misses most merged branches. TRIGGER when: local repo has accumulated stale branches after fanout sessions, worktree cleanup, or manual sweeps. DO NOT TRIGGER when: working on a clean repo with few branches or when branch deletion is handled by another skill (e.g. dev10x:fanout teardown).
How it works
- Overview
- Orchestration
- Workflow
- Integration Note (GH-463)
- Anti-Patterns
SKILL.md preview
--- name: dev10x:git-branch-prune description: > Classify and prune stale local branches with merge verification, designed for rebase-merge repos where `git branch --merged` misses most merged branches. TRIGGER when: local repo has accumulated stale branches after fanout sessions, worktree cleanup, or manual sweeps. DO NOT TRIGGER when: working on a clean repo with few branches or when branch deletion is handled by another skill (e.g. dev10x:fanout teardown). user-invocable: true invocation-name: dev10x:git-branch-prune allowed-tools: - AskUserQuestion - mcp__plugin_dev10x_cli__detect_base_branch - Bash(git fetch --prune:*) - Bash(git branch:*) - Bash(git worktree list:*) - Bash(git log:*) - Bash(git worktree prune:*) - Bash(git rev-parse:*) - Bash(git merge-base:*) --- # Git Branch Prune Classify and prune stale local branches with merge verification. Handles repos that rebase-merge (tip of merged branch is NOT an ancestor of develop), where the naive `git branch --merged` + `grep ': gone]'` pipeline misses most stale branches. ## Overview **Why the naive pipeline fails in rebase-merge repos:** - `gone` tracking catches only branches whose remote was deleted on merge — usually a minority of stale branches. - `git branch --merged develop` misses rebased commits because the tip is typically not an ancestor of develop after a rebase-merge. - Never-pushed worktree branches (e.g. `worktree-agent-*`) have no upstream at all, so they never appear as `gone`. This skill implements a validated 4-category classification that catches all three failure modes while surfacing branches with real unpublished work. ## Orchestration **REQUIRED: Create tasks before ANY work.** Execute these `TaskCreate` calls at startup: 1. `TaskCreate(subject="GH-464 Classify and prune stale branches", activeForm="Classifying branches")` Mark completed when done: `TaskUpdate(taskId, status="completed")` **Announce:** "Using dev10x:git-branch-prune to classify and prune stale local branches." ## Workflow ### Step 1: Detect Base Branch Call `mcp__plugin_dev10x_cli__detect_base_branch` to determine the base branch (prefers `develop`/`development`, falls back to `main`/`master`/`trunk`). Use this throughout — never hardcode `develop`. ### Step 2: Fetch and Prune Remotes Run `git fetch --prune` to remove stale remote-tracking refs before classification. ### Step 3: Collect Live Worktrees Run `git worktree list --porcelain` and extract the `HEAD` commit SHA for each worktree path. A branch checked out in a live worktree must never be deleted — skip any branch whose tip SHA matches a live worktree HEAD. ### Step 4: Classify Each Local Branch Skip the following branches unconditionally: - The currently checked-out branch - `main`, `master`, `develop`, `development`, `trunk` - Any branch checked out in a live worktree (Step 3) For each remaining branch, apply this decision tree in order: **Category A — `gone` upstream (safe `-D`):** `git branch -vv` shows `: gone]` — remote was deleted (typically on merge via GitHub). Safe to delete with `git branch -D`. **Category B — no upstream, tip is ancestor of base (safe `-d`):** Branch has no upstream (`git branch -vv` shows no `[...]` tracking info) AND `git merge-base --is-ancestor <tip> origin/<base>` returns 0. Zero unique commits — safe to delete with `git branch -d`. **Category C — no upstream, tip not ancestor, content-matched (safe `-D` after verification):** Branch has no upstream AND the tip is NOT an ancestor of base. Run rebase-merge content check: `git log origin/<base>..HEAD --oneline` lists commits unique to this branch. For each unique commit, check whether its title or a TICKET-ID from the branch name appears in `git log origin/<base> --oneline --grep=<subject>`. If all unique commits are found (content landed on base), safe to delete with `git branch -D`. If content check fails, move to Category D. **Category D — keep and surface:** All other branches: tracking a live upstream with `ahead N` commits, or content-check failed (Category C fallback), or undecidable state. Do NOT delete. Surface to user with reason. ### Step 5: Present Categories and Request Approval **REQUIRED: Call `AskUserQuestion`** (do NOT use plain text). Present the classified branch list and ask the user to approve deletions per category: Gate options (present all four options): - **Delete A + B + C** — Remove all auto-safe and content-verified branches (recommended when C list was inspected and looks correct) - **Delete A + B only** — Remove only unambiguously safe branches; inspect Category C manually first - **Delete A only** — Remove only `gone`-upstream branches; most conservative - **Skip all deletions** — Exit without deleting anything; just show the report Include in the gate presentation: - Count per category (e.g. "Category A: 14 branches") - Full branch names per category, formatted as a code block - Category D branches with per-branch reason for keeping ### Step 6: Execute Approved Deletions Delete branches in the approved categories using the appropriate flag: - Category A and C: `git branch -D <name>` (force-delete) - Category B: `git branch -d <name>` (safe-delete) Catch and report any deletion errors individually — do not abort the batch on a single failure. ### Step 7: Cleanup Run `git worktree prune` to remove stale worktree administrative files. If `git` warned about unreachable loose objects during any of the above steps, suggest the user run `git prune` separately (do not run it automatically — it can be slow on large repos). ### Step 8: Report Print a summary: - Branches deleted per category - Branches kept (Category D) with reasons - Any deletion errors Mark the task completed. ## Integration Note (GH-463) The dev10x:fanout skill's worktree teardown step may delegate its per-session branch-deletion to this skill in a future iteration. This skill is designed for standalone invocation and does not require or import any fanout-specific state. ## Anti-Patterns - Never delete the currently checked-out branch. - Never delete branches checked out in live worktrees. - Never run `git branch -D` on a Category D branch without explicit user confirmation beyond the Step 5 gate. - Never hardcode `develop` — always use the detected base branch. - Do NOT run `git prune` automatically — suggest it only when gc warns.
Files in this package (2)
- SKILL.md 6 KB
- evals/evals.json 5 KB
Versions
The database has no other skills named dev10x:git-branch-prune.
Database snapshot: 13.11.2026 · package version a1abb2efc974 (SHA-256 digest of the entire package)
Downloads in the last 30 days: 0 · ranking
Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.
Similar skills
- 100cleanup-branches
Prune local branches whose work is already merged into the base. TRIGGER when the user says "clean up branches", "delete merged branches", "prune local branches", "remove old branches", "I have too many branches", "what branches can I delete", "/nyann:cleanup-branches". Do NOT… - 100cleaning-up-branches
Deletes merged git branches (local and remote) and flags stale unmerged branches for manual review. Use when user mentions "cleanup branches", "delete merged branches", "prune old branches", "remove stale branches", "branch cleanup", or runs /cleanup-branches command. - 100git-branch-cleanup
Safely clean up stale local and remote git branches - find which branches are really merged (including squash-merged and rebase-merged ones that `git branch --merged` misses), which have unpushed or unmerged work, and delete only the safe ones with a restore list. Use this… - 100branch-cleanup
Prune stale git branches after a merge wave: delete closed/merged remote branches, remove local tracking branches that no longer exist on the remote, and optionally clean up local branches already merged to main. Use after running dependabot-triage, after a sprint wind-down, or… - 100branch-cleanup
Prune stale git branches after a merge wave: delete closed/merged remote branches, remove local tracking branches that no longer exist on the remote, and optionally clean up local branches already merged to main. Use after running dependabot-triage, after a sprint wind-down, or… - 100clean-branches
Delete local branches whose PRs have been merged upstream. Checks GitHub PR status for each branch. Triggers on: clean branches, delete merged branches, prune branches, branch cleanup.