git-branch-cleanup
Analyze and safely clean up local Git branches with interactive categorization, safety guards, and worktree support.
Introduction
The git-branch-cleanup skill is a specialized utility designed for developers and DevOps engineers looking to maintain a tidy local development environment. Over time, local Git repositories often accumulate stale, merged, or orphaned branches that clutter development workflows and increase cognitive load. This skill automates the identification and safe removal of these branches by categorizing them based on their relationship with the base branch (e.g., main or master), their last commit activity, and their remote tracking status.
-
Categorizes branches into specific buckets: Merged (safe to delete), Remote Deleted (gone), Stale (30+ days without activity), Unmerged (active), and those associated with Git worktrees.
-
Implements strict safety guards to protect critical branches like main, master, trunk, and currently checked-out branches from accidental deletion.
-
Provides an interactive, step-by-step workflow: analyze current state, review safety classifications, confirm deletions, and execute cleanups.
-
Supports advanced Git features, including the detection and proper management of git worktree associations to prevent filesystem corruption during deletion.
-
Features a dry-run mode for users to preview branch deletions before any commands are executed, ensuring full control over repository maintenance.
-
Leverages standard Git commands like for-each-ref, branch --merged, and branch -vv to ensure reliability across standard Git installations.
-
Recommended for developers managing large repositories with high branch turnover or those following agile workflows with frequent feature branches.
-
The tool requires Git 2.17+ for full worktree support and Git 2.22+ for optimal branch identification capabilities.
-
Typical use cases include cleaning up post-merge branches, pruning branches linked to deleted remote PRs, and identifying long-forgotten experimental branches.
-
Users should note that the 'Stale' threshold is configurable; the default 30-day window can be tuned based on specific team sprint cycles or project requirements.
-
The skill distinguishes between safe 'git branch -d' deletions for merged branches and force '-D' deletions for unmerged or orphaned branches, providing clear guidance on when each is appropriate.
Repository Stats
- Stars
- 382
- Forks
- 26
- Open Issues
- 3
- Language
- Python
- Default Branch
- main
- Sync Status
- Idle
- Last Synced
- May 1, 2026, 07:05 AM