git-worktree-prune
БесплатноЗапускает вложенные скриптыНе проверенSafely prune stale git worktrees and local branches left over from past sessions, deleting only those with no unique work so no commit is ever lost. Use when…
от ZacheryGlass★ 602 звезды на GitHubОб этом скилле
Git Worktree & Branch Prune
Remove stale worktrees and local branches from old sessions without ever losing a commit.
Safety invariant
- A branch is deleted only when every commit on it is reachable from some other surviving ref (another local branch, a remote-tracking branch
origin/*, or a tag). Branches with unique commits are kept. - A worktree is removed only when it is clean (no uncommitted or untracked changes). The branch it held is preserved.
- A clean worktree that still holds ignored sensitive files (
.env, private keys, local*.db/*.sqlite,.npmrc, etc.) is kept, sincegit worktree removewould delete those local-only files. Non-sensitive ignored files (build caches,node_modules) don't block removal, but the entry count is reported. Override with--remove-ignored. - The primary worktree, the current branch,
main/master, and the repo's detected default branch (fromorigin/HEADorinit.defaultBranch, e.g.trunk/develop) are always kept.
Usage
Always dry-run first (the default — it changes nothing), review the plan, then apply:
python scripts/prune_git.py --repo <path> # dry-run: prints KEEP/REMOVE/DELETE plan
python scripts/prune_git.py --repo <path> --apply # execute after reviewing the dry-run
Flags:
--fetch— rungit fetch --all --prunefirst so branches already merged/pushed to a remote are recognized as deletable. Without it the tool is more conservative (stale remotes only ever cause it to keep more, never lose work).--remove-ignored— allow removal of clean worktrees even when they hold ignored sensitive files like.env(default: keep them).--protect BRANCH— always keep this branch (repeatable). Use for branches with no unique commits that you still want to keep (see below).--repo PATH— a path inside the target repo (default: cwd).
Review the DELETE list before --apply
The "no unique commits" rule is about commits, not intent. A branch can be flagged DELETE while still being meaningful — most commonly a feature branch that a descendant now subsumes (e.g., you branched research/x off feat/y, so feat/y's commits now also live on research/x). No commit is lost if it's deleted, but the branch name and its PR track are. Keep such a branch with --protect <name>.
Every removal is printed with its reason; a branch shown as KEEP -- N unique commit(s) holds work found nowhere else and is never touched.
Notes
- Never deletes remote-tracking refs, tags, or the reflog — only local branches and worktree checkouts.
- Removing a worktree that holds a branch (even a protected one like
main) frees the branch without deleting it; you can then check it out in the primary worktree. - Worktrees whose directory is already gone are cleaned via
git worktree prune. - Sensitive-file detection matches the basenames git reports for
status --ignored. A sensitive file nested inside an ignored directory (git reports only the directory) isn't individually flagged — rare, but review the REMOVE list's "N ignored entries" note if unsure. - On Windows, run under Git Bash / a UTF-8 console (
PYTHONIOENCODING=utf-8) if paths contain non-ASCII characters.
Установить git-worktree-prune в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл git-worktree-prune?
Safely prune stale git worktrees and local branches left over from past sessions, deleting only those with no unique work so no commit is ever lost. Use when a repo has accumulated worktrees and branches over many sessions and needs cleanup. Triggers include "prune worktrees", "delete stale branches", "clean up git worktrees/branches", "remove old worktrees", "which branches are safe to delete".
Как установить скилл git-worktree-prune?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл git-worktree-prune запускает скрипты?
Да, скилл несёт исполняемые скрипты. Проверь исходник перед установкой.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic