Agent skill

git-cleanup

Safely analyzes and cleans up local git branches and worktrees by categorizing them as merged, squash-merged, superseded, or active work.

trailofbitsgithub.com/trailofbitsGitHub ↗
claude-codecan modify filesCC-BY-SA-4.0
Install
npx skills add trailofbits/skills --skill git-cleanup --agent claude-code

Same command for any agent — swap --agent for codex, cursor, copilot.

Facts
Files in the skill folder: 3
SKILL.md size: 12 KB
Bundled scripts: none
Allowed tools: BashReadGrepAskUserQuestion
Path: plugins/git-cleanup/skills/git-cleanup/SKILL.md
Open the folder on GitHub →
Where it comes from
Stars: 6,426
Language: Python
Read our review of the source →

Weekly change comes from our own snapshots, not the repository page — it measures attention, not adoption.

From the SKILL.md

# 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)

What's inside
Steps it walks through
  1. When to Use
  2. When NOT to Use
  3. Core Principle: SAFETY FIRST
  4. Critical Implementation Notes
  5. Squash-Merged Branches Require Force Delete
  6. Group Related Branches BEFORE Categorization
  7. Thorough PR History Investigation
  8. Workflow
  9. Phase 1: Comprehensive Analysis
  10. Phase 2: Group Related Branches
  11. Phase 3: Categorize Remaining Branches
  12. Phase 4: Dirty State Detection
  13. GATE 1: Present Complete Analysis
  14. GATE 2: Final Confirmation with Exact Commands
Ships with 2 files
  • agents/openai.yaml
  • assets/trail-of-bits-mark.svg
Commands it runs
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
More from skills
All skills →
About this skill
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.

Keep going