Skip to content
Back to skills

Prune Branches

ASecurity

Cleans up local git branches marked as [gone] (deleted on the remote but still present locally), including removing any associated worktrees. Use when the user says "prune branches", "clean up gone branches", "/prune-branches", or asks to delete stale local branches whose remotes are gone.

  • 3 stars
  • 0 votes
  • 0 copies
  • 5 views
  • Added September 1, 2026
developmentgobashgit

Security analysis

A100/100

Scanned September 1, 2026

npx -y skills add samuelpatro/.claude --skill prune-branches --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Prune Branches?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Prune Branches
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/samuelpatro-prune-branches/badge)](https://www.skillsdirectory.com/skills/samuelpatro-prune-branches)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: prune-branches
effort: low
allowed-tools: Bash(git branch:*), Bash(git worktree:*), Bash(git rev-parse:*)
description: >
  Cleans up local git branches marked as [gone] (deleted on the remote but still
  present locally), including removing any associated worktrees.
  Use when the user says "prune branches", "clean up gone branches", "/prune-branches",
  or asks to delete stale local branches whose remotes are gone.
---

## Your task

Delete every local branch whose upstream is gone, removing any attached worktree first. If nothing is marked `[gone]`, report that and stop.

## Steps

1. **List branches with verbose status** to surface `[gone]` markers and any `+` prefix indicating an attached worktree:

   ```bash
   git branch -v
   ```

2. **List worktrees** so you know which paths will be removed:

   ```bash
   git worktree list
   ```

3. **Remove worktrees and delete `[gone]` branches** in one pass. Strips the `+`/`*`/space prefix, finds the worktree (if any), and force-deletes the branch:

   ```bash
   git branch -v | grep '\[gone\]' | sed 's/^[+* ]//' | awk '{print $1}' | while read branch; do
     echo "Processing branch: $branch"
     worktree=$(git worktree list | grep "\\[$branch\\]" | awk '{print $1}')
     if [ ! -z "$worktree" ] && [ "$worktree" != "$(git rev-parse --show-toplevel)" ]; then
       echo "  Removing worktree: $worktree"
       git worktree remove --force "$worktree"
     fi
     echo "  Deleting branch: $branch"
     git branch -D "$branch"
   done
   ```

## Reporting

- Print which worktrees were removed and which branches were deleted.
- If no `[gone]` branches exist, say "No cleanup needed" and stop.
- Never delete branches that are not marked `[gone]`.
- Never touch the current working tree's root path.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.