git-cleanup

Verifies a branch's PR merged via gh, then deletes the branch and refreshes the default branch.

Updated Dec 18, 2025
One-click install
npx skills add https://github.com/l0lxl0lw/dotfiles --skill git-cleanup-l0lxl0lw
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: git-cleanup
Source: https://github.com/l0lxl0lw/dotfiles/tree/main/ai/shared/skills/git/git-cleanup
Command: npx skills add https://github.com/l0lxl0lw/dotfiles --skill git-cleanup-l0lxl0lw

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) components.

What problem does it solve? After a pull request merges, developers often forget to delete the feature branch or, worse, delete a branch whose work never actually landed upstream — losing commits permanently. This Skill gates all destructive actions behind an authoritative GitHub merge check, then safely removes the local and remote branch and fast-forwards the default branch. ## Core Features & Use Cases - Hard merge verification gate: Uses gh pr view to confirm PR state is MERGED with a non-null mergedAt before anything destructive runs, correctly handling squash and rebase merges where the local commit graph looks unmerged. - Safe branch deletion: Refreshes the default branch with git pull --ff-only, deletes the local branch with -d (falling back to -D only when the merge is verified), and removes the remote branch if GitHub did not auto-delete it. - Worktree and divergence handling: Detects linked worktrees (Orca ADE) where branch switching is impossible, and halts with a clear error when the local default branch has diverged from origin. - Use Case: You just merged PR #42 from branch feature/login. Ask the assistant to clean up after the merge — it confirms the PR merged, switches to main, pulls the latest, and deletes feature/login locally and remotely. ## Quick Start Tell the assistant: the PR for my current branch is merged, clean up the branch and switch me back to main.

Frequently Asked Questions about git-cleanup

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I safely delete a git branch after its PR is merged?

Verify the PR state is MERGED with a non-null mergedAt using gh pr view, then switch to the default branch, pull with --ff-only, and delete the branch locally and remotely. Never rely on git branch -d alone, since squash merges make merged branches look unmerged.

Why does git branch -d refuse to delete a branch whose PR already merged?

After a squash or rebase merge, the branch's commits are not ancestors of the default branch, so git considers it not fully merged. The gh CLI's PR state is authoritative; once MERGED is confirmed, a forced -D delete is safe.

Can I clean up a branch inside a linked git worktree?

A linked worktree cannot switch to the default branch or delete the branch it is standing on. The cleanup script fast-forwards the default branch by ref, deletes the remote branch, and prints the orca worktree rm command for the user to run.

What happens if my local main branch has diverged from origin?

The cleanup script exits with code 10 and does not delete the feature branch. A diverged default branch usually means a commit landed directly on it by mistake; resolve the divergence with the user first, then re-run the cleanup.

Does this work if the PR was closed without merging?

No. A CLOSED PR with a null mergedAt is treated as not merged, and the verification script exits with code 5 to block deletion. Deleting such a branch would permanently lose work that never reached the default branch.