prune-branches

Deletes local git branches marked as gone and removes their associated worktrees.

3|1|Updated Aug 23, 2025
One-click install
npx skills add https://github.com/samuelpatro/.claude --skill prune-branches-samuelpatro
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: prune-branches
Source: https://github.com/samuelpatro/.claude/tree/main/skills/prune-branches
Command: npx skills add https://github.com/samuelpatro/.claude --skill prune-branches-samuelpatro

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Local repositories accumulate stale branches whose remote counterparts have been deleted, cluttering branch lists and leaving orphaned worktrees on disk. This Skill automates the cleanup of those [gone] branches in a single pass. ## Core Features & Use Cases - Gone Branch Detection: Scans git branch -v output for [gone] markers to identify branches deleted on the remote. - Worktree Removal: Detects worktrees attached to stale branches and removes them with git worktree remove --force before deleting the branch. - Safe Deletion: Only touches branches explicitly marked [gone], never deletes the current working tree root, and reports every removal. - Use Case: After a sprint where many feature branches were merged and deleted on the remote, run this Skill to clean up all local leftovers and their worktrees at once. ## Quick Start Ask the assistant to prune branches or clean up gone branches in the current repository.

Frequently Asked Questions about prune-branches

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I delete local git branches deleted on the remote?▼

Run git branch -v to find branches marked [gone], then delete each with git branch -D. This Skill automates that loop, also removing any attached worktrees before deleting the branch.

How to remove git worktrees for stale branches?▼

List worktrees with git worktree list, match each stale branch to its worktree path, then run git worktree remove --force on that path. The Skill performs this matching and removal automatically for all [gone] branches.

Does pruning gone branches delete the current working tree?▼

No. The Skill explicitly compares each candidate worktree path against git rev-parse --show-toplevel and skips the current working tree root, so your active checkout is never removed.

Will this delete branches that are not marked gone?▼

No. Only branches whose upstream shows the [gone] marker in git branch -v output are deleted. Branches with active or never-pushed upstreams are left untouched.

Why does git branch -v not show gone for my deleted remote branch?▼

The [gone] marker only appears after the local remote-tracking ref is updated, typically via git fetch --prune. Fetch with pruning first so git knows the upstream branch was deleted.