midnite-git-cleanup

Remove merged local branches, worktrees, and origin branches using ancestry, patch-equivalence, and merged-PR checks.

Updated Sep 1, 2026
One-click install
npx skills add https://github.com/bilo-io/midnite-studio --skill midnite-git-cleanup-bilo-io
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: midnite-git-cleanup
Source: https://github.com/bilo-io/midnite-studio/tree/main/.agents/skills/midnite-git-cleanup
Command: npx skills add https://github.com/bilo-io/midnite-studio --skill midnite-git-cleanup-bilo-io

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Stale branches and worktrees pile up after merges, and git branch -d falsely refuses to delete branches whose work landed as duplicate commits, cherry-picks, or squash merges, leaving repositories cluttered with refs that hold no unique work. ## Core Features & Use Cases - Three-test staleness detection: Combines git merge-base --is-ancestor, git cherry patch-equivalence, and gh pr list --state merged lookup by headRefOid to catch ordinary merges, cherry-picks, and squash-merged PRs. - Dry-run by default with explicit opt-ins: Prints STALE, KEEPING, and BLOCKED reports and changes nothing until --apply is passed; remote deletion requires the separate --prune-remote flag. - Safety guardrails: Never touches the target or current branch, skips dirty worktrees instead of forcing, warns about stashes anchored outside the target branch, and leaves gc/reflog expiry to the user. - Use Case: After a sprint of squash-merged PRs, run the dry run to see which of 16 lingering origin branches actually landed, confirm with the user, then apply local and remote deletion in one pass. ## Quick Start Run the cleanup script in dry-run mode against the default branch, show me the stale local and remote branch lists, and ask for confirmation before deleting anything.

Frequently Asked Questions about midnite-git-cleanup

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

FAQPage Schema
How do I delete git branches that are already merged?▼

Run the cleanup script in dry-run mode first to list branches that fully landed on the target branch, then re-run with `--apply` after confirming. It deletes ancestors with `git branch -d` and patch-equivalent duplicates with `-D`.

Why does git branch -d say my branch is not fully merged?▼

`git branch -d` only checks ancestry (reachability), not content. A branch whose work landed as a duplicate commit or cherry-pick carries the same diff under a different SHA, so it is unreachable and refused even though it holds nothing unique.

How do I find and delete squash-merged remote branches on GitHub?▼

Squash merges rewrite commits into a new SHA, so ancestry and patch-id checks both miss them. The script queries `gh pr list --state merged` and matches each remote branch tip against the merged PR's `headRefOid`, then deletes with `--apply --prune-remote`.

Does the cleanup script delete branches without confirmation?▼

No. It is dry-run by default and only prints the plan. Local deletion requires `--apply`, and remote deletion requires the separate `--prune-remote` flag, and the skill instructs showing the dry-run output and getting an explicit yes first.

What happens to dirty worktrees or stashes during branch cleanup?▼

A stale branch with a dirty worktree is reported under BLOCKED and skipped, since the script never passes `--force` to `git worktree remove`. Stashes anchored to commits outside the target branch trigger a warning, because deleting branches could leave their base dangling.