From 531b59f538b9d601fcbc480e20dd0a703b026516 Mon Sep 17 00:00:00 2001 From: Simon <10131203+gaomeng1900@users.noreply.github.com> Date: Wed, 8 Apr 2026 17:28:11 +0800 Subject: [PATCH] chore: add `git-cleanup` skill --- .github/skills/git-cleanup/SKILL.md | 64 +++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 .github/skills/git-cleanup/SKILL.md diff --git a/.github/skills/git-cleanup/SKILL.md b/.github/skills/git-cleanup/SKILL.md new file mode 100644 index 0000000..73add67 --- /dev/null +++ b/.github/skills/git-cleanup/SKILL.md @@ -0,0 +1,64 @@ +--- +name: git-cleanup +description: Clean up local git branches and remotes accumulated from PR reviews. Use when the user asks to clean branches, remove stale remotes, or tidy up the local git state. +--- + +# 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: + +```bash +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 + +```bash +# 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 +``` + +### 4. Remove Remotes + +```bash +git remote | grep -v '^origin$' | xargs -I{} git remote remove {} +``` + +### 5. Confirm + +```bash +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