From workflow
Use this skill when user wants to clean up local git branches whose remote tracking branches are gone/deleted. Triggers on phrases like "clean branches", "delete stale branches", "prune branches", "git branch clean", "dọn branch", "xóa branch cũ".
How this skill is triggered — by the user, by Claude, or both
Slash command
/workflow:git-branch-cleanThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Sync remote state, then find and delete local branches whose remote is gone. Always confirm with user before any deletion.
Sync remote state, then find and delete local branches whose remote is gone. Always confirm with user before any deletion.
git fetch --prune
This removes remote-tracking refs that no longer exist on remote.
Get list of alive tracking branches (not gone, not current):
git branch -vv | grep -v ': gone]' | grep -v '^\*' | grep '\[origin/' | awk '{print $1}'
For each branch in that list, fast-forward update it locally (no checkout needed):
git fetch origin "<branch>:<branch>" 2>/dev/null && echo "Updated: <branch>" || echo "Skipped (diverged): <branch>"
Run one git fetch origin <branch>:<branch> per branch. If it fails (diverged), skip silently — don't block. Print result per branch so user can see progress.
Also pull current branch:
git pull --ff-only 2>/dev/null || echo "Current branch: skipped (diverged or no upstream)"
git branch -vv | grep ': gone]' | awk '{print $1}'
If no stale branches found:
"No stale branches. Local repo is clean."
Stop here.
If stale branches found, show list and ask user:
"Found [N] local branch(es) whose remote is gone:
[list each branch on its own line]
Delete all? (yes/no)"
Wait for user reply before continuing.
If user says no → Stop. Tell user no branches were deleted.
If user says yes → Run:
git branch -vv | grep ': gone]' | awk '{print $1}' | xargs git branch -D
Report each deleted branch and confirm done.
| Error | Action |
|---|---|
| Not inside a git repo | "Not a git repo. Run from project root." |
git fetch fails (no remote / auth error) | Show error output. Stop. |
| Branch delete fails (e.g., currently checked out) | Show which branch failed, skip it, delete the rest |
| No branches at all | "Repo has no local branches to check." |
git branch -D (force delete) because gone branches have no upstream — -d would refuse.Fetching and pruning... done.
Found 3 local branch(es) whose remote is gone:
feature/old-login
fix/AUTH-99-typo
chore/remove-deprecated-api
Delete all? (yes/no)
User types yes:
Deleted: feature/old-login
Deleted: fix/AUTH-99-typo
Deleted: chore/remove-deprecated-api
Done. 3 branch(es) removed.
Guides creation, editing, and verification of skills for AI coding agents using test-driven development with subagent scenarios. Use when authoring or debugging skills.
npx claudepluginhub nguyenhuy158/skills --plugin workflow