git-cleanup-branches
SKILL.md
Git Branch Cleanup
Automatically identifies and removes local git branches that track remote branches that no longer exist (marked as "gone").
When to Use This Skill
- User asks to "clean up git branches"
- User wants to "remove deleted branches"
- User mentions "prune branches" or "cleanup stale branches"
- Local branches show
[origin/branch: gone]status - After merging pull requests and deleting remote branches
Prerequisites
- Git repository initialized
- Must be on main/master branch (not on a branch you want to delete)
- Active internet connection to fetch from remote
Workflow
1. Switch to main branch (Required)
git checkout main
Important: You cannot delete a branch you're currently on. Always switch to main/master first.
2. Check current branch status
git branch -vv
Look for branches with [origin/branch-name: gone] - these track deleted remotes.
3. Prune remote tracking references
git fetch --prune
4. Find stale branches
PowerShell:
git branch -vv | Select-String 'gone'
Bash:
git branch -vv | grep 'gone'
5. Delete stale branches
Single branch:
git branch -D <branch-name>
Automated cleanup (PowerShell):
git branch -vv | Select-String 'gone' | ForEach-Object {
$branchName = $_.Line.Trim() -split '\s+' | Select-Object -First 1
git branch -D $branchName
}
Automated cleanup (Bash):
git branch -vv | grep 'gone' | awk '{print $1}' | xargs -r git branch -D
6. Verify cleanup
git branch -vv
Safety Notes
- Always switch to main/master before cleaning - you can't delete the branch you're on
- Use
-D(force delete) - bypasses merge check - Deleted local branches can't be easily recovered
- Remote branches are NOT affected - this only cleans local copies
- Backup branches (no remote tracking) won't be deleted by this process
Weekly Installs
3
Repository
pickleboxer/skillsFirst Seen
Mar 1, 2026
Security Audits
Installed on
opencode3
gemini-cli3
github-copilot3
codex3
kimi-cli3
amp3