From sync-local-branches
Use when the user wants to update all local branches to their latest remote commits and delete local branches whose remote has been merged/deleted (post-PR cleanup). Handles "sync all branches", "prune merged branches", "clean up local branches", "整理 local branch".
How this skill is triggered — by the user, by Claude, or both
Slash command
/sync-local-branches:sync-local-branchesThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Fast-forward every local branch with an upstream, then delete local branches that are clearly merged:
Fast-forward every local branch with an upstream, then delete local branches that are clearly merged:
gone (standard PR-merged + remote-deleted signal).gh pr create).git merge but whose remote still exists → use git branch --merged main logic insteadgit fetch --all --prune — update remote refs, remove deleted remote branches locally.gone:
git fetch . <upstream>:<branch> (works without checkout; refuses non-FF, safe).git merge --ff-only @{u} (purely local — fetch already happened in step 2).gone (standard "remote merged + remote deleted" case).git cherry primary branch shows no + lines — covers squash-merge with missing upstream tracking).git branch -D because squash-merged branches are not recognized as merged by -d. Never delete the current branch or main/master/develop/trunk.gone, or (b) has the same tip as the primary branch (merged). Only report them; never auto-remove.If the summary lists stale worktrees, ask the user whether to clean them up before doing anything. For each confirmed entry, run:
git worktree remove <path>
git branch -D <branch>
Never remove a worktree without confirmation — the user may have uncommitted work or deliberate parked state there.
The bundled script is at ${CLAUDE_PLUGIN_ROOT}/skills/sync-local-branches/sync.sh. If that variable isn't expanded, locate sync.sh under the plugin's installation directory at skills/sync-local-branches/sync.sh. Run it from the target git repo's root:
bash <path-to-sync.sh> # apply
bash <path-to-sync.sh> --dry-run # preview
# Detect "remote merged & deleted" branches:
git branch -vv | awk '/: gone\]/ {print $1}' | sed 's/^\*\s*//'
# Detect "no upstream + already merged" (incl. squash merges):
# git cherry shows '+' for unmerged commits; no '+' lines = fully merged.
git cherry main feature-branch | grep -q '^+' || echo "merged — safe to delete"
# Fast-forward a non-checked-out branch safely:
git fetch . "origin/feature-x:feature-x" # refuses non-FF, no checkout needed
| Mistake | Fix |
|---|---|
Using git branch --merged main to find merged branches | Misses squash merges. Use : gone] + git cherry instead. |
Running git pull in a loop with git checkout | Slow, dirties reflog, may conflict. Use git fetch . up:branch. |
Deleting with -d | Fails on squash-merged branches. Use -D after confirming upstream is gone or all commits are in primary. |
Forgetting --prune on fetch | Upstream-gone detection won't work. |
Deleting main/current branch | Always guard with an allowlist + current-branch check. |
main, master, develop, trunk, or the current branch.--dry-run prints what would be deleted without touching anything.Creates, edits, and optimizes skills for Claude Code, including drafting, evaluating with test prompts, iterating on performance, and improving skill descriptions for better triggering accuracy.
npx claudepluginhub chechunhsu/plugins --plugin sync-local-branches