Skip to content

Instantly share code, notes, and snippets.

@tylergaw
Created February 20, 2026 16:50
Show Gist options
  • Select an option

  • Save tylergaw/7dcab47336f33d439f00cff8250241f8 to your computer and use it in GitHub Desktop.

Select an option

Save tylergaw/7dcab47336f33d439f00cff8250241f8 to your computer and use it in GitHub Desktop.
Local git cleanup skill

Skill: Git Cleanup After Merge

Slash Command

/cleanup-git

Description

After merging a PR, this command finds the most recently merged branch using the GitHub CLI, confirms with the user, then checks out main, pulls with prune, and deletes the merged branch.

Steps

  1. Run the following to get the most recently merged PR's branch name:

    gh pr list --state merged --limit 1 --json headRefName --jq '.[0].headRefName'
    
  2. Show the user the branch name and ask: "Found recently merged branch: {branch}. Run cleanup? (checkout main, pull --prune, delete branch)"

  3. Wait for explicit confirmation before proceeding.

  4. If confirmed, run these commands in sequence:

    git checkout main
    git pull --prune
    git branch -D {branch}
    
  5. Report the result of each command. If any command fails, stop and report the error without running subsequent commands.

Notes

  • Requires gh CLI to be installed and authenticated
  • The branch deletion uses -D (force delete) since squash-merged branches won't appear as fully merged to git
  • This only looks at merged PRs on the remote, not local branch state
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment