git-cleanup
Safely analyzes and cleans up local git branches and worktrees by categorizing them as merged, squash-merged, superseded, or active work.
npx skills add trailofbits/skills --skill git-cleanup --agent claude-code
Same command for any agent — swap --agent for codex, cursor, copilot.
Weekly change comes from our own snapshots, not the repository page — it measures attention, not adoption.
# Git Cleanup Safely clean up accumulated git worktrees and local branches by categorizing them into: safely deletable (merged), potentially related (similar themes), and active work (keep). ## When to Use - When the user has accumulated many local branches and worktrees - When branches have been merged but not cleaned up locally - When remote branches have been deleted but local tracking branches remain ## When NOT to Use - Do not use for remote branch management (this is local cleanup only) - Do not use for repository maintenance tasks like gc or prune - Not designed for headless or non-interactive automation (requires user confirmations at two gates) ## Core Principle: SAFETY FIRST **Never delete anything without explicit user confirmation.** This skill uses a gated workflow where users must approve each step before any destructive action. ## Critical Implementation Notes ### Squash-Merged Branches Require Force Delete **IMPORTANT:** `git branch -d` will ALWAYS fail for squash-merged branches because git cannot detect that the work was incorporated. This is expected behavior, not an error. When you identify a branch as squash-merged: - Plan to use `git branch -D` (force delete)
- When to Use
- When NOT to Use
- Core Principle: SAFETY FIRST
- Critical Implementation Notes
- Squash-Merged Branches Require Force Delete
- Group Related Branches BEFORE Categorization
- Thorough PR History Investigation
- Workflow
- Phase 1: Comprehensive Analysis
- Phase 2: Group Related Branches
- Phase 3: Categorize Remaining Branches
- Phase 4: Dirty State Detection
- GATE 1: Present Complete Analysis
- GATE 2: Final Confirmation with Exact Commands
Extract common prefixes from branch names git log --oneline "$default_branch".."$branch" Search by: branch name, commit message keywords, PR numbers git log --oneline "$default_branch" | grep -iE "(branch-name|keyword|#[0-9]+)" git log --oneline "$default_branch" | grep -iE "(#[0-9]+)" | head -20 Get default branch name Protected branches - never analyze or delete List all local branches with tracking info git branch -vv List all worktrees
What does the git-cleanup skill do?
Safely analyzes and cleans up local git branches and worktrees by categorizing them as merged, squash-merged, superseded, or active work.
How do I install it?
Run `npx skills add trailofbits/skills --skill git-cleanup --agent claude-code` — it drops the skill into your project so the agent can pick it up. Swap the --agent value for codex, cursor or copilot if you use one of those.
Where does this skill come from?
From trailofbits/skills, a repository with 6,426 stars. We read it straight from the repository tree rather than a submitted listing, so what you see here is what is actually published.
Is a popular skill a good skill?
Not necessarily. Stars measure attention, not adoption — a repository can trend for a week and be abandoned. That is why we show the weekly change from our own snapshots next to the total, instead of a single flattering number.
