Skip to main content
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 Brodin

When 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
Important: This skill only runs when explicitly invoked. It will never suggest cleanup proactively or run automatically.

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

  1. Analysis Review - User reviews categorization before proceeding
  2. Deletion Confirmation - User confirms exact commands before execution
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.
Blocks removal of worktrees with uncommitted changes. Shows clear warnings about data loss.
Never touches protected branches: main, master, develop, release/*
Flags [gone] branches (remote deleted) for review instead of auto-deleting. May have local-only work.

Installation

Usage Example

1

Invoke the Skill

2

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
3

Review Categorized Results

Claude presents categorized tables:
4

Choose What to Delete

5

Confirm Exact Commands

Claude shows exact commands:
6

Execute Deletions

Claude runs each deletion separately and reports results.

Workflow Details

Phase 1: Comprehensive Analysis

Claude gathers ALL information upfront:
Before individual categorization, identify branch groups by shared prefixes:
For each group:
  1. Compare commit histories - Which branches contain commits from others?
  2. Find merge evidence - Which PRs incorporated work from this group?
  3. Identify the “final” branch - Usually most recent or most complete
  4. 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
Name prefix alone is NOT sufficient.

Phase 3: Categorize Remaining Branches

For branches NOT in a related group:

Phase 4: Dirty State Detection

Check ALL worktrees for uncommitted changes:
Display warnings prominently:

Squash-Merged Branches

IMPORTANT: git branch -d will ALWAYS fail for squash-merged branches because git cannot detect that the work was incorporated.
When Claude identifies a branch as squash-merged:
  • Plans to use git branch -D (force delete) from the start
  • Does NOT try git branch -d first
  • Shows git branch -D in the confirmation step
  • This is expected behavior, not an error
Squash-merged detection:

Safety Rules

Example Output

Rationalizations to Reject

The skill teaches Claude to reject these shortcuts:
  • 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