About git-cleanup
git-cleanup is a skill for removing stale local branches and non-origin remotes after work such as reviewing multiple PRs. It includes checks and confirmation steps to protect the current branch and unmerged work.
Key features
- 01Survey branches, remotes, status, and stashes
- 02Check for uncommitted changes and ahead branches
- 03Separate unmerged branches for review
- 04Remove branches and non-origin remotes safely
- 05Confirm the remaining branches and remotes
Use cases
- 01Clean up tracking branches after reviewing several PRs
- 02Remove contributor remotes no longer needed
Install
Copy the command and run it in a terminal.
$
npx skills add https:/ / github.com/ alibaba/ page-agent --skill git-cleanupAfter installing, type/git-cleanupin Claude Code to confirm it loaded.
Details
From the project READMEGit Cleanup
Clean local branches (except main and current branch) and non-origin remotes.
Useful after reviewing multiple PRs that leave behind tracking branches and contributor remotes.
Workflow
1. Survey
Run these in parallel:
git branch
git remote
git status --short
git stash list
Present a summary of how many branches and remotes will be removed.
2. Safety Checks — Ask Before Proceeding
Stop and ask for confirmation if any of these are true:
- Current branch is NOT
main - Working tree has uncommitted changes or stashes
- Any branch is ahead of its upstream
List unmerged branches separately and let the user decide.
3. Delete Branches
# Safe delete first (fails on unmerged branches)
git branch | grep -v '^\*' | grep -v '^\s*main$' | xargs git branch -d 2>&1
# Force-delete only with explicit user approval
git branch -D <branch>
4. Remove Remotes
git remote | grep -v '^origin$' | xargs -I{} git remote remove {}
5. Confirm
git branch && echo "---" && git remote
Report what was cleaned up.
Key Rules
- NEVER delete
mainor the current checked-out branch - NEVER force-delete unmerged branches without user confirmation
- If in doubt, ask
Comments
Markdown supported