agentleFS
coryparrrycoryparrry/codex-skills/skills/git-clean-merged-branch/SKILL.md

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

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
  1. Distinctive:

    Use this skill to return a repo to a clean local Git state after the current branch has already been merged on GitHub.

    line 8
  2. Distinctive:

    Treat those as shorthand for: fetch GitHub, update the default branch, and remove the old local branch safely.

    line 17
  3. Distinctive:

    Do not continue if the worktree has uncommitted or untracked changes.

    line 22
  4. Very specific:

    Prefer the repo default branch from origin/HEAD.

    line 23
  5. Distinctive:

    Use git fetch --prune before deciding what exists remotely.

    line 24
  6. Distinctive:

    Use fast-forward-only pulls for the default branch.

    line 25
  7. Distinctive:

    Delete the local branch only after switching away from it.

    line 26
  8. Distinctive:

    Prefer safe branch deletion with git branch -d.

    line 27
  9. Distinctive:

    If safe deletion fails because GitHub used squash or rebase merge, verify the merged GitHub PR and compare the branch diff against the …

    line 28
  10. Distinctive:

    Use forced branch deletion without merge verification only when the user has clearly said the branch is merged or no longer needed, and …

    line 29
  11. Very specific:

    Delete the old remote branch only after verifying the fetched remote tip is safe.

    line 30
  12. Distinctive:

    Never run git reset --hard, git clean, or other broad destructive cleanup for this workflow.

    line 31
  13. Distinctive:

    Stop if there are local changes and explain that the user needs to commit, stash, or discard them first.

    line 37
  14. Distinctive:

    If the starting branch was not the default branch, delete the local starting branch.

    line 42
  15. Distinctive:

    If normal deletion fails, let the script verify a merged GitHub PR and exact diff equality before using git branch -D.

    line 43
  16. Distinctive:

    Delete the old remote branch after local cleanup succeeds and the fetched remote tip is verified safe.

    line 44
  17. Distinctive:

    Update relevant documents as when this prompt is sent, it means the end of a phase/slice.

    line 46
  18. Very specific:

    Use scripts/clean_merged_branch.sh from this skill for the standard cleanup.

    line 50
  19. Distinctive:

    Run it from the repo root or any directory inside the target repo:

    line 52
  20. Distinctive:

    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 …

    line 58
  21. Very specific:

    Do not use --force-delete-unmerged when the user only asks for a status check or is unsure whether the branch was merged.

    line 72

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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 branch
  • sort git
  • branch merged
  • git-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 to main, then master.
  • Use git fetch --prune before 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-remote when the user explicitly asks to preserve it.
  • Never run git reset --hard, git clean, or other broad destructive cleanup for this workflow.

Recommended Workflow

  1. Confirm the current directory is inside a Git repo.
  2. Record the current branch name.
  3. Stop if there are local changes and explain that the user needs to commit, stash, or discard them first.
  4. Fetch from origin with pruning.
  5. Resolve the default branch.
  6. Switch to the default branch.
  7. Pull the default branch with fast-forward-only.
  8. If the starting branch was not the default branch, delete the local starting branch.
  9. If normal deletion fails, let the script verify a merged GitHub PR and exact diff equality before using git branch -D.
  10. Delete the old remote branch after local cleanup succeeds and the fetched remote tip is verified safe.
  11. Show the final git status --short --branch.
  12. 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.sh

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 because GitHub used squash or rebase merge, rerun with:

bash /path/to/skill/scripts/clean_merged_branch.sh --force-delete-unmerged

The 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-remote

Do 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

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.