cleaning-up-merged-branches
Skill41 starsChanged 41 days agoMITView on GitHub
Syncs main and deletes the local feature branch after a PR is merged on GitHub. Use when the user says they merged or squash-merged a PR ("I merged PR 411 on GitHub", "merged the PR", "clean up the branch"). Codifies this repo's squash-merge default, where `git branch -d` wrongly reports "not fully merged" and a verified force-delete is required.
- Commits and pushes
In this repository33 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .github/copilot-instructions.mdCopilot instructions
- branch-preflightSkill
- diagnoseSkill
- grill-meSkill
- grill-with-docsSkill
- handoffSkill
- improve-codebase-architectureSkill
- inkwell-retrofitSkill
- open-knowledgeSkill
- pb-collectionSkill
- reviewable-pr-slicingSkill
- setup-matt-pocock-skillsSkill
- shadcnSkill
- shipSkill
- source-command-build-nextSkill
- source-command-qcheckSkill
- source-command-triage-prsSkill
- to-issuesSkill
- verify-frontend-changeSkill
- branch-preflightSkill
- claude-code-primitivesSkill
- cleaning-up-merged-branchesSkill
- inkwell-retrofitSkill
- pb-collectionSkill
- reviewable-pr-slicingSkill
- verify-frontend-changeSkill
- verify-gsdSkill
- verify-remindersSkill
- verify-sync-convergenceSkill
- verify-sync-sessionSkill
- verify-task-tombstonesSkill
The file
Files
Cleaning up merged branches
Sync main and remove the now-stale local feature branch after the user merges a
PR on GitHub. This repo squash-merges PRs by default, so the plain git branch -d
refuses to delete the branch — verify the content actually landed in main, then
force-delete.
Steps
- Fetch, prune stale remote-tracking refs, and note the current branch:
git fetch origin --prune && git branch --show-current - Switch to
mainand pull the merge (localmainstill points at the pre-merge commit until you do this):git checkout main && git pull origin main - Try the safe delete of the feature branch:
git branch -d <branch>- Succeeds → done; go to Verify.
- Fails with
error: the branch '<branch>' is not fully merged→ expected for a squash merge. GitHub squashed the branch into one new commit, so its original commits are not ancestors ofmaineven though the content landed. Continue.
- Confirm the branch's content is fully in
mainbefore force-deleting. The':!.blume'pathspec excludes local.blume/tool artifacts that are never committed:git diff main <branch> -- . ':!.blume'- Empty output → content is fully in
main; safe to force-delete. - Non-empty output → the branch has unmerged changes. Stop, show the diff to the user, and do NOT force-delete.
- Empty output → content is fully in
- Force-delete the redundant local branch:
git branch -D <branch>
Verify
git branchshows the feature branch is gone and you are onmain.git log --oneline -1showsmainat the squash-merge commit.
Gotchas
- Deleting multiple branches at once: zsh does not word-split an unquoted
variable (unlike bash), so
git branch -D $branchespasses the whole list as one bad refspec and deletes nothing. Pipe the list throughxargsinstead:... | xargs git branch -D. - Deleting remote branches (
git push origin --delete <branch>) is externally visible — confirm with the user first. Local cleanup above does not require it;git fetch origin --prunealready drops stale remote-tracking refs.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

