git-worktree-prune

Prune stale git worktrees and local branches without losing any commits.

599|54|Updated Aug 21, 2025
One-click install
npx skills add https://github.com/ZacheryGlass/.claude --skill git-worktree-prune
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: git-worktree-prune
Source: https://github.com/ZacheryGlass/.claude/tree/main/skills/git-worktree-prune
Command: npx skills add https://github.com/ZacheryGlass/.claude --skill git-worktree-prune

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) components.

What problem does it solve?

Long-running projects accumulate leftover git worktrees and local branches from past sessions, cluttering the repository and making it hard to tell which branches still hold unique work. Manual cleanup risks deleting branches that contain commits found nowhere else.

Core Features & Use Cases

  • Safe branch deletion: A branch is deleted only when every commit on it is reachable from another surviving ref (local branch, remote-tracking branch, or tag), so no commit is ever lost.
  • Clean worktree removal: Worktrees are removed only when they have no uncommitted or untracked changes; the primary worktree, current branch, and main/master are always protected.
  • Dry-run by default: Prints a full KEEP/REMOVE/DELETE plan with reasons before changing anything, and supports --protect flags for branches you want to keep despite having no unique commits.
  • Use Case: After weeks of parallel agent sessions, your repo has a dozen worktrees and thirty local branches. Run the dry-run, review the plan, protect any branch names you want to keep, then apply to reclaim a clean repository.

Quick Start

Ask the agent to prune stale worktrees and branches in this repository, starting with a dry-run so you can review the plan before applying it.

Frequently Asked Questions about git-worktree-prune

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

FAQPage Schema
How do I safely delete stale git branches without losing commits?

Delete a branch only when every commit on it is reachable from another ref such as another local branch, a remote-tracking branch, or a tag. This skill automates that check with git rev-list and prints a KEEP/DELETE plan before applying anything.

How do I remove old git worktrees left over from past sessions?

Run the prune script against the repository; it lists each worktree and removes only those that are clean with no uncommitted or untracked changes. Worktrees whose directories are already gone are cleaned via git worktree prune.

Can a branch with no unique commits still be worth keeping?

Yes. A feature branch subsumed by a descendant branch has no unique commits but its name and PR track may still matter. Pass --protect <branch> to keep such branches; the flag is repeatable.

Does git worktree pruning delete remote branches or tags?

No. The tool never deletes remote-tracking refs, tags, or the reflog. It only removes local branches and worktree checkouts, and the primary worktree, current branch, and main/master are always kept.

Why does the tool keep a branch I expected to be deleted?

A branch is kept when it holds commits not reachable from any other ref, reported as KEEP with the count of unique commits. Stale remote-tracking refs can also make it more conservative; run with --fetch to update remotes first.