| name | cleanup-branches |
| description | Batch git branch cleanup - generates single approval script |
Git Branch Cleanup (Batched)
Created: 2026-02-09-00-00
Last Updated: 2026-02-09-00-00
This skill analyzes git branches and generates a SINGLE bash script for you to approve and run, eliminating the need for individual permission approvals on each git branch -D command.
Process
-
Analyze all local branches
- Get list of all branches
- Check merge status
- Check remote tracking status
- Check last commit date
-
Categorize branches for deletion
Safe to delete (merged):
- Branches fully merged to main/master
- No unique commits
Stale branches:
- No remote tracking branch
- Last commit > 14 days ago
- Not currently checked out
Pattern-based candidates:
- temp-, test-, wip-, experiment-
- feature/* that are merged
- bugfix/* that are merged
-
Generate cleanup script
- Group by category with comments
- Add safety check (show what will be deleted)
- Make copyable for user approval
-
Present summary + script
Output Format
#!/bin/bash
echo "🔍 Branches to be deleted:"
echo ""
echo "Merged branches (safe):"
git branch -D feature/completed-work
git branch -D bugfix/old-fix
echo ""
echo "Stale branches (no remote, >14 days old):"
git branch -D temp-experiment
git branch -D wip-abandoned
echo ""
echo "Pattern-based cleanup:"
git branch -D test-something
echo ""
echo "✅ Cleanup complete! Deleted X branches."
Critical Rules
NEVER run git branch -D commands directly - This skill ONLY generates scripts for user approval.
Safety checks before including in script:
- Branch is not currently checked out
- Branch is not main/master/develop
- Branch is not protected by name patterns (release-, hotfix-)
- For stale branches: verify no unpushed commits
Usage
/cleanup-branches
Execution
When invoked, perform these steps:
- Run
git branch -a to get all branches
- For each local branch, check:
git branch --merged main (or master)
git for-each-ref --format='%(refname:short) %(upstream:track)' refs/heads/
git log -1 --format=%ci <branch> for last commit date
- Categorize branches based on analysis
- Generate the script with clear categorization
- Present summary statistics
- Show the copyable script
- Remind user to review before running
Do NOT:
- Run any git branch -D commands yourself
- Delete branches without user explicitly running the script
- Include branches with unpushed commits
- Include protected branch patterns
Example output:
📊 Branch Analysis Complete
Found 40 total local branches:
- 11 merged to main (safe to delete)
- 8 stale (no remote, >14 days old)
- 3 pattern-based (temp-*, test-*)
- 18 active (keeping)
Generated cleanup script below ↓
Copy and run this script to delete 22 branches:
[script here]
⚠️ Review carefully before running!