cleanup-git-worktrees

Audit and safely remove merged or stale Git worktrees and local branches.

74|11|Updated Jul 4, 2024
One-click install
npx skills add https://github.com/OpenSourceAGI/qwksearch-research-agent --skill cleanup-git-worktrees-opensourceagi
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: cleanup-git-worktrees
Source: https://github.com/OpenSourceAGI/qwksearch-research-agent/tree/main/apps/qwk-in-lobe/.agents/skills/cleanup-git-worktrees
Command: npx skills add https://github.com/OpenSourceAGI/qwksearch-research-agent --skill cleanup-git-worktrees-opensourceagi

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) components.

What problem does it solve? Repositories accumulate abandoned Git worktrees and stale local branches over time, and deleting them manually risks losing uncommitted work or removing branches that were never merged. This Skill audits every worktree and branch, classifies each by safety status, and removes only verified cleanup candidates. ## Core Features & Use Cases - Deterministic Audit: Classifies each worktree and branch as protected-dirty, protected-current, candidate-merged, candidate-gone, review-no-upstream, active, or protected-branch using a bundled Bash script. - Guarded Cleanup: Re-audits every target immediately before deletion, refuses anything not classified as merged or gone, and defaults to dry-run mode unless --apply is passed. - Use Case: After finishing several feature branches, run the audit to see which worktrees are fully merged into the base branch, present the table to the user for approval, then remove only the confirmed candidates and report remaining counts. ## Quick Start Ask the assistant to audit all Git worktrees and local branches against the base branch and safely clean up the ones that are fully merged or whose remote upstream is gone.

Frequently Asked Questions about cleanup-git-worktrees

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

FAQPage Schema
How do I safely remove old Git worktrees and branches?

Run the audit command to classify every worktree and branch, review the table of candidates, then pass exact branch names to the clean command with --apply. The script re-audits each target immediately before deletion and refuses anything not merged or gone.

How to find Git branches already merged into the main branch?

Use git merge-base --is-ancestor to test whether a branch is contained in the base ref, which the audit script does automatically. Branches fully contained in the base are classified as candidate-merged and become eligible for cleanup.

Does a gone upstream branch mean it was merged?

No, a [gone] upstream only means the remote branch was deleted, which often happens after squash merges or rebases without proving containment. The audit classifies these separately as candidate-gone and recommends checking GitHub PR state when the distinction matters.

Will cleanup delete worktrees with uncommitted changes?

No, any worktree with modified or untracked files is classified as protect-dirty and is never removed. The clean command also refuses to delete the current worktree, protected branches like main, or branches lacking merge or gone-upstream evidence.

Can I preview Git worktree cleanup before deleting anything?

Yes, the clean command runs as a dry run by default and prints each target branch, worktree path, and classification without deleting anything. Deletion only occurs when you explicitly pass the --apply flag.