git-clean-merged-branch
Skill3 starsChanged 5 months agoMITView on GitHub
Safely clean up a local Git branch after it has been merged on GitHub. Use when the user says short commands like "clean merged branch", "cleanup merged branch", "sort git", "clean up git", "branch merged", "merged branch cleanup", or invokes "git-clean-merged-branch"; also use for longer requests that say the branch has been merged and is no longer needed.
- Deletes or force-pushes
In this repository8 other files it gives its agents.
- AGENTS.mdAGENTS.md
- appstore-readiness-auditSkill
- codex-routingSkill
- continue-deep-researchSkill
- deep-code-reviewSkill
- research-repo-technologySkill
- swift-code-reviewSkill
- triage-review-commentsSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
21 rules. About 0 are common, 17 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈17
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 8
Use this skill to return a repo to a clean local Git state after the current branch has already been merged on GitHub.
- Distinctive: line 17
Treat those as shorthand for: fetch GitHub, update the default branch, and remove the old local branch safely.
- Distinctive: line 22
Do not continue if the worktree has uncommitted or untracked changes.
- Very specific: line 23
Prefer the repo default branch from origin/HEAD.
- Distinctive: line 24
Use git fetch --prune before deciding what exists remotely.
- Distinctive: line 25
Use fast-forward-only pulls for the default branch.
- Distinctive: line 26
Delete the local branch only after switching away from it.
- Distinctive: line 27
Prefer safe branch deletion with git branch -d.
- Distinctive: line 28
If safe deletion fails because GitHub used squash or rebase merge, verify the merged GitHub PR and compare the branch diff against the …
- Distinctive: line 29
Use forced branch deletion without merge verification only when the user has clearly said the branch is merged or no longer needed, and …
- Very specific: line 30
Delete the old remote branch only after verifying the fetched remote tip is safe.
- Distinctive: line 31
Never run git reset --hard, git clean, or other broad destructive cleanup for this workflow.
- Distinctive: line 37
Stop if there are local changes and explain that the user needs to commit, stash, or discard them first.
- Distinctive: line 42
If the starting branch was not the default branch, delete the local starting branch.
- Distinctive: line 43
If normal deletion fails, let the script verify a merged GitHub PR and exact diff equality before using git branch -D.
- Distinctive: line 44
Delete the old remote branch after local cleanup succeeds and the fetched remote tip is verified safe.
- Distinctive: line 46
Update relevant documents as when this prompt is sent, it means the end of a phase/slice.
- Very specific: line 50
Use scripts/clean_merged_branch.sh from this skill for the standard cleanup.
- Distinctive: line 52
Run it from the repo root or any directory inside the target repo:
- Distinctive: line 58
If the user's wording clearly says the branch is already merged or no longer needed, and safe deletion reports the branch is not merged …
- Very specific: line 72
Do not use --force-delete-unmerged when the user only asks for a status check or is unsure whether the branch was merged.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Git Clean Merged Branch
Use this skill to return a repo to a clean local Git state after the current branch has already been merged on GitHub.
The user may intentionally use a short trigger such as:
clean merged branchsort gitbranch mergedgit-clean-merged-branch
Treat those as shorthand for: fetch GitHub, update the default branch, and remove the old local branch safely.
Core Rules
- Inspect before changing anything.
- Do not continue if the worktree has uncommitted or untracked changes.
- Prefer the repo default branch from
origin/HEAD; fall back tomain, thenmaster. - Use
git fetch --prunebefore deciding what exists remotely. - Use fast-forward-only pulls for the default branch.
- Delete the local branch only after switching away from it.
- Prefer safe branch deletion with
git branch -d. - If safe deletion fails because GitHub used squash or rebase merge, verify the merged GitHub PR and compare the branch diff against the merged PR diff before deleting the local branch with
git branch -D. - Use forced branch deletion without merge verification only when the user has clearly said the branch is merged or no longer needed, and after the repo is clean and the default branch is updated.
- Delete the old remote branch only after verifying the fetched remote tip is safe; use
--keep-remotewhen the user explicitly asks to preserve it. - Never run
git reset --hard,git clean, or other broad destructive cleanup for this workflow.
Recommended Workflow
- Confirm the current directory is inside a Git repo.
- Record the current branch name.
- Stop if there are local changes and explain that the user needs to commit, stash, or discard them first.
- Fetch from
originwith pruning. - Resolve the default branch.
- Switch to the default branch.
- Pull the default branch with fast-forward-only.
- If the starting branch was not the default branch, delete the local starting branch.
- If normal deletion fails, let the script verify a merged GitHub PR and exact diff equality before using
git branch -D. - Delete the old remote branch after local cleanup succeeds and the fetched remote tip is verified safe.
- Show the final
git status --short --branch. - Update relevant documents as when this prompt is sent, it means the end of a phase/slice.
Script
Use scripts/clean_merged_branch.sh from this skill for the standard cleanup.
Run it from the repo root or any directory inside the target repo:
bash /path/to/skill/scripts/clean_merged_branch.shIf the user's wording clearly says the branch is already merged or no longer needed, and safe deletion reports the branch is not merged because GitHub used squash or rebase merge, rerun with:
bash /path/to/skill/scripts/clean_merged_branch.sh --force-delete-unmergedThe script now verifies squash-merged branches by default before force-deleting locally. Use --force-delete-unmerged only when GitHub verification is unavailable or insufficient and the user has clearly accepted local branch deletion.
The script deletes the old remote branch by default after local cleanup succeeds. To preserve the old remote branch, run:
bash /path/to/skill/scripts/clean_merged_branch.sh --keep-remoteDo not use --force-delete-unmerged when the user only asks for a status check or is unsure whether the branch was merged.
Output
Tell the user:
- which branch was cleaned up
- which default branch was updated
- whether the old local branch was deleted
- whether deletion used merge diff verification
- whether the old remote branch was deleted
- whether the final repo state is clean
- any action still needed if cleanup stopped
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.

