npx skills add SpecterOps/skills --skill git-cleanupSKILL.md
Git Repository Cleanup
Repository hygiene: prune branches, detect stale work, and check repo health.
Parse the user's input to determine the action:
$git-cleanupor$git-cleanup branches— find and prune merged/stale branches$git-cleanup stale [days]— branches with no commits in N days (default 30)$git-cleanup health— large files, dangling refs, worktrees, repo size$git-cleanup all— scan all git repos under ~/Projects/
Prerequisites
- Verify we're in a git repository (
git rev-parse --is-inside-work-tree) — except forallaction which scans directories - If not in a git repo (and not using
all), tell the user and stop
Protected Branches
The following branches are NEVER suggested for deletion: main, master, develop
Action: branches (default)
- Fetch latest remote state:
git fetch --prune - Identify the default branch (
git symbolic-ref refs/remotes/origin/HEAD 2>/dev/nullor fall back tomain/master) - Find merged branches:
git branch --merged <default>— local branches already merged into default- Exclude protected branches and current branch
- Find branches with deleted remotes:
git branch -vv— look for[origin/...: gone]entries
- Present findings as a dry-run preview:
- List branches that can be safely deleted (merged)
- List branches whose remote is gone
- Show last commit date and message for each
- Ask the user which branches to delete (or "all listed")
- On confirmation, delete with
git branch -d <branch>(safe delete) - If a branch fails
-d(unmerged), warn the user and offer-Dwith explicit explanation that commits may be lost — only proceed with user confirmation
Action: stale [days]
- Default to 30 days if no argument provided
- For each local branch (excluding protected branches):
- Get last commit date:
git log -1 --format='%ci' <branch> - Calculate age in days
- Get last commit date:
- List branches older than the threshold, sorted by age (oldest first)
- Show for each: branch name, last commit date, last commit message, age in days
- Present as dry-run preview — ask before deleting
- On confirmation, use
git branch -dfirst; offer-Donly with warning if unmerged
Action: health
Run a comprehensive repository health check:
Repository size:
.gitdirectory size:du -sh .git- Working tree size:
du -sh . --exclude=.git(or equivalent) - Object count:
git count-objects -vH
Large files (top 10 by size in history):
git rev-list --objects --all | git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)' | awk '/^blob/ {print $3, $4}' | sort -rn | head -10- Flag files over 10MB
Dangling objects:
git fsck --no-reflogs 2>&1— look for dangling commits, blobs, trees- Report count and suggest
git gcif significant
Worktrees:
git worktree list— show active worktrees
Remote status:
git remote -v— list remotes- Check if local is ahead/behind remote
Stale tracking branches:
git remote prune origin --dry-run— branches that would be pruned
Present findings with recommendations
If cleanup is recommended (gc, prune), show the commands but always ask before running them
Action: all
- Find all git repositories under
~/Projects/:find ~/Projects -maxdepth 3 -name .git -type d
- For each repository found: a. Show repo name and path b. Run the branches check (merged + gone remotes) c. Show summary: N merged branches, M gone-remote branches
- Per-repo confirmation — ask before deleting branches in each repo
- Show overall summary at the end
Safety Rules
- Never delete without confirmation — always preview first
- Never delete protected branches (main, master, develop)
- Never
git push origin --deleteon protected branches - Never run
git gcwithout asking - Always preview first — every action starts as a dry run
- Per-repo confirmation for
all— don't batch-delete across repos - Use
git branch -d(safe delete) first; only offer-Dwith explicit warning