skills/branch-cleanup-after-pr/SKILL.md
Sync local branches after a PR is merged. Checkout main, pull, fetch --prune, delete local branches that are merged or track gone remotes. Use when a PR was just merged (merge, squash, or rebase) or when local branch list is stale.
npx skillsauth add pkuppens/pkuppens branch-cleanup-after-prInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
When a PR is merged (merge commit, squash-merge, or rebase-merge), run this to sync local state and remove obsolete branches.
Complements maintenance-cleanup (broader hygiene) and git-worktrees — use worktrees when branch deletion fails.
Checkout main, pull
git checkout main
git pull
Fetch with prune (removes refs for deleted remote branches)
git fetch --prune
Identify branches to delete
git branch --merged main — branch tip is in main's historygit branch -vv | grep ': gone]' — remote ref was deleted on GitHubgit cherry -v main <branch>-, the branch changes are already in main even when ancestry differsDelete local branches
--merged list (exclude protected branches), run git branch -d <name>: gone] list:
git branch -d <name>git cherry -v main <name>-, delete with git branch -D <name> (safe because patches already exist in main)| Type | Detection | Notes |
|------|-----------|-------|
| Merge commit | --merged main | Branch tip is ancestor of main |
| Squash merge | git cherry -v main <branch> | Commits often appear as - even if --merged misses them |
| Rebase merge | git cherry -v main <branch> | Same pattern as squash merge |
| Cherry-pick merge | git cherry -v main <branch> | Patch-equivalent commits appear as - |
Never delete: main, master, develop, release/*, hotfix/*
Select-String instead of grep; chain with ; not && where neededSome repos keep copy-paste commands under .cursor/commands/branch-cleanup.md — optional.
testing
Syncs remote default branch locally (checkout, fetch --prune, pull) and returns to the previous branch when it still exists. Reports stashes and worktrees not yet handled. Use when the user asks to sync main, update default branch, fetch/pull origin, or run /sync-branch.
tools
Creates, queries, updates, and links Azure Boards work items via az boards CLI. Use when filing ADO work items, running WIQL queries, or setting area path, iteration, tags, and assignee.
tools
Creates, reviews, and completes Azure Repos pull requests and branch policies via az repos CLI. Use when opening ADO PRs, setting required reviewers, or configuring build validation policies.
development
Guides Azure Pipelines YAML structure, build validation on PRs, and staged deployment with environments and approvals. Use when authoring azure-pipelines.yml or configuring CI/CD on Azure DevOps.