cleanup-git-worktrees

Audit and remove stale Git worktrees and local branches using deterministic classification logic.

82.1k|15.8k|Updated May 21, 2023
One-click install
npx skills add https://github.com/lobehub/lobehub --skill cleanup-git-worktrees
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: cleanup-git-worktrees
Source: https://github.com/lobehub/lobehub/tree/main/.agents/skills/cleanup-git-worktrees
Command: npx skills add https://github.com/lobehub/lobehub --skill cleanup-git-worktrees

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) components.

What problem does it solve?

This Skill addresses the accumulation of abandoned Git worktrees and stale local branches that clutter development environments and complicate repository management.

Core Features & Use Cases

  • Deterministic Audit: Classifies worktrees and branches as active, merged, or gone based on remote tracking and base branch containment.
  • Safe Cleanup: Performs dry-run validations before executing deletions to prevent accidental loss of uncommitted work or active development branches.
  • Use Case: Use this after completing multiple feature branches to identify and remove worktrees that are no longer needed, keeping your local repository state clean and performant.

Quick Start

Run the audit command to list all worktrees and branches with their current status.

Frequently Asked Questions about cleanup-git-worktrees

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

FAQPage Schema
How do I identify which Git worktrees are safe to delete?

Run the audit command to classify worktrees. The script marks worktrees as 'candidate-merged' or 'candidate-gone' only when they are fully contained in the base branch or their upstream has been pruned, ensuring safety.

Does this skill delete my uncommitted changes?

No, the script explicitly checks for dirty worktrees and classifies them as 'protect-dirty'. It refuses to perform cleanup on any worktree containing modified or untracked files to prevent data loss.

Can I use this to clean up branches that aren't in worktrees?

Yes, the audit process scans all local branches in the repository. You can pass any local branch name to the clean command, provided it meets the safety criteria for deletion.

What happens if I try to delete a protected branch?

The script includes a protection mechanism for critical branches like 'main' or 'canary'. It will refuse to delete these, even if requested, to maintain repository integrity.