mcpField
G
git-cleanup

git-cleanup

github.com/alibabaDevelopment29.6k40 installsUpdated 8w ago
Repository

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

  1. 01Survey branches, remotes, status, and stashes
  2. 02Check for uncommitted changes and ahead branches
  3. 03Separate unmerged branches for review
  4. 04Remove branches and non-origin remotes safely
  5. 05Confirm the remaining branches and remotes

Use cases

  1. 01Clean up tracking branches after reviewing several PRs
  2. 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-cleanup

After installing, type/git-cleanupin Claude Code to confirm it loaded.

Details

From the project README

Git 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 main or the current checked-out branch
  • NEVER force-delete unmerged branches without user confirmation
  • If in doubt, ask

Comments

Markdown supported