Safely clean up accumulated git worktrees and local branches by categorizing them as merged, squash-merged, superseded, or active work. Requires explicit user confirmation before any deletions.
Overview
The Git Cleanup skill analyzes your local git repository and categorizes branches/worktrees into safe-to-delete, needs-review, and keep categories. It uses a gated workflow requiring explicit user confirmation before any deletions. Author: Henrik BrodinWhen to Use
Invoke with/git-cleanup when:
- You have accumulated many local branches and worktrees
- Branches have been merged but not cleaned up locally
- Remote branches have been deleted but local tracking branches remain
- You want to identify which branches are safe to delete
Categories
Branches and worktrees are categorized as:Safe to Delete
Branches fully merged into the default branch. Uses safe delete (
git branch -d).Squash-Merged
Work incorporated via squash merge (git can’t detect). Uses force delete (
git branch -D).Superseded
Part of a related branch group, work verified in main via PR or in newer branch. Uses force delete (
git branch -D).Needs Review
Branches with deleted remotes (
[gone]) where work NOT found in main. Manual review required.Active Work
Branches with unpushed commits or untracked local branches. Keep these.
Safety Features
Two Confirmation Gates
Two Confirmation Gates
- Analysis Review - User reviews categorization before proceeding
- Deletion Confirmation - User confirms exact commands before execution
Safe Delete Preference
Safe Delete Preference
Uses
git branch -d (safe delete) for merged branches. Only uses git branch -D (force delete) for squash-merged branches where git cannot detect the merge.Uncommitted Changes Detection
Uncommitted Changes Detection
Blocks removal of worktrees with uncommitted changes. Shows clear warnings about data loss.
Protected Branches
Protected Branches
Never touches protected branches:
main, master, develop, release/*Gone Branch Review
Gone Branch Review
Flags
[gone] branches (remote deleted) for review instead of auto-deleting. May have local-only work.Installation
Usage Example
Claude Analyzes Repository
Claude runs comprehensive analysis:
- Lists all local branches with tracking info
- Identifies merged branches
- Checks recent PR merge history
- Groups related branches by prefix
- Detects squash-merged branches
- Checks for uncommitted changes in worktrees
Workflow Details
Phase 1: Comprehensive Analysis
Claude gathers ALL information upfront:Phase 2: Group Related Branches
Before individual categorization, identify branch groups by shared prefixes:- Compare commit histories - Which branches contain commits from others?
- Find merge evidence - Which PRs incorporated work from this group?
- Identify the “final” branch - Usually most recent or most complete
- Mark superseded branches - Older iterations whose work is in main or newer branch
SUPERSEDED requires evidence, not just shared prefix:
- A PR merged the work into main, OR
- A newer branch contains all commits from the older branch
Phase 3: Categorize Remaining Branches
For branches NOT in a related group:Phase 4: Dirty State Detection
Check ALL worktrees for uncommitted changes:Squash-Merged Branches
When Claude identifies a branch as squash-merged:- Plans to use
git branch -D(force delete) from the start - Does NOT try
git branch -dfirst - Shows
git branch -Din the confirmation step - This is expected behavior, not an error
Safety Rules
Example Output
Rationalizations to Reject
Related Skills
- GH CLI - Works alongside for GitHub PR/issue management
- Ask Questions If Underspecified - Uses similar confirmation gate pattern
- Second Opinion - Can review branch diffs before cleanup