origin-git-cleanup

Surveys, classifies, and cleans git branches and worktrees after finished work.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) components.

What problem does it solve? After finishing a chunk of work, repositories accumulate merged feature branches, stale worktrees, unpushed commits, and stray edits. Cleaning them up by hand is error-prone — deleting the wrong branch destroys parallel work, while squash merges make merged branches look unmerged. This Skill brings a repository to a clean, on-main, synced state without losing anyone's work. ## Core Features & Use Cases - Read-only survey first: A bundled script snapshots branches, worktrees, stashes, PRs, and merge state before anything is touched, including patch-equivalence detection for squash-merged branches. - Explicit classification: Every branch and worktree is labeled integrate, delete, keep, or investigate with evidence, so parallel work and open PRs are never deleted by mistake. - Safe execution order: Commits, pushes, merges via GitHub PR squash or local fast-forward, syncs main with origin, then deletes approved branches and worktrees using reversible commands only. - Use Case: After a PR is merged, ask the assistant to tidy up — it commits remaining changes, merges the branch, returns the root worktree to main, deletes the merged branch locally and remotely, and reports a clean tree. ## Quick Start Ask the assistant to clean up the repository now that the current branch's work is finished and merged.

Frequently Asked Questions about origin-git-cleanup

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

FAQPage Schema
How do I clean up git branches after merging a PR?

Run a read-only survey of branches, worktrees, and PRs first, then classify each branch as integrate, delete, keep, or investigate. Delete only branches confirmed merged with git branch -d after switching back to main, and retire remote refs separately.

Why does a squash-merged branch show as not merged in git?

Squash merges create a new commit on main, so the feature branch's commits are not ancestors of main and git branch --merged omits it. Confirm merge status via the PR state or check whether git diff main..HEAD is empty before deleting.

Can I delete the git branch I am currently on?

No, git refuses to delete the checked-out branch. Switch the root worktree back to main first, then run git branch -d on the finished branch and delete its remote tracking ref afterward.

Does this work with repositories that have no GitHub remote?

Yes. Without a GitHub remote it uses a local fast-forward merge into main instead of a gh PR squash merge. The survey script detects the remote type and adjusts the merge strategy accordingly.

When should I not delete a git worktree?

Never remove a worktree with uncommitted changes or one checked out for active parallel work. Dirty worktrees require an explicit decision to commit, stash, keep, or discard, and forced removal needs explicit user approval.