Agent Skillslobehub/lobehub › cleanup-git-worktrees

cleanup-git-worktrees

GitHub

审计并安全清理 Git worktrees 和过期本地分支,通过脚本分类候选项,经用户确认后删除,保护脏数据和当前工作区。

.agents/skills/cleanup-git-worktrees/SKILL.md lobehub/lobehub

Trigger Scenarios

列出或审计 Git worktrees 清理已合并或上游消失的过期分支 整理过期的 worktree 注册信息

Install

npx skills add lobehub/lobehub --skill cleanup-git-worktrees -g -y
More Options

Non-standard path

npx skills add https://github.com/lobehub/lobehub/tree/canary/.agents/skills/cleanup-git-worktrees -g -y

Use without installing

npx skills use lobehub/lobehub@cleanup-git-worktrees

指定 Agent (Claude Code)

npx skills add lobehub/lobehub --skill cleanup-git-worktrees -a claude-code -g -y

安装 repo 全部 skill

npx skills add lobehub/lobehub --all -g -y

预览 repo 内 skill

npx skills add lobehub/lobehub --list

SKILL.md

Frontmatter
{
    "name": "cleanup-git-worktrees",
    "description": "Audit and safely clean Git worktrees and stale local branches. Use when asked to list worktrees, identify completed or merged branches, remove worktrees whose remote branches are gone, prune stale worktree registrations, or clean local branches without losing uncommitted work."
}

Cleanup Git Worktrees

Use the bundled script to make classification deterministic. Treat cleanup as a destructive action: audit first, show the exact candidates, and obtain explicit user approval before applying deletion unless the user's current request already names the exact targets.

Workflow

  1. Run the audit from any worktree in the repository:

    bash .agents/skills/cleanup-git-worktrees/scripts/cleanup.sh audit --fetch --base origin/canary
    

    Omit --fetch only when network access is unavailable; disclose that remote state may be stale.

  2. Interpret classifications:

    • protect-dirty: preserve; it has modified or untracked files.
    • protect-current: preserve; never remove the worktree running the command.
    • candidate-merged: clean and fully contained in the base branch.
    • candidate-gone: clean and its configured upstream was pruned. This is stale, but not proof of merge after squash/rebase.
    • review-no-upstream: clean but lacks an upstream and is not contained in the base.
    • active: retain unless the user explicitly identifies it as finished.
    • protected-branch: never delete main, canary, or the base branch.
  3. Present a compact table containing path, branch, dirty count, upstream state, base containment, and classification. Keep candidate-merged separate from candidate-gone; do not describe [gone] as proof of merge.

  4. After approval, pass exact branch names to cleanup:

    bash .agents/skills/cleanup-git-worktrees/scripts/cleanup.sh clean \
      --base origin/canary \
      --branch feat/example \
      --branch fix/example \
      --apply
    

    Without --apply, cleanup is a dry run. The script re-audits every target immediately before deletion.

  5. Run the audit again and report:

    • removed worktrees and branches;
    • retained dirty/current targets;
    • remaining worktree and local-branch counts;
    • any partial deletion or Git error.

Safety rules

  • Never discard dirty worktrees merely because their branch is merged or [gone].
  • Never use recursive deletion to bypass git worktree remove. If Git partially removes a directory, stop and inspect the exact path before deciding how to recover.
  • Never force-delete a branch that is neither contained in the base nor [gone] through this script.
  • A deleted upstream indicates staleness, not necessarily merge. Use GitHub PR state when the distinction matters.
  • Preserve unrelated user changes and concurrent worktrees.
  • Prefer git fetch --prune origin before classification and git worktree prune only for registrations whose directories are already missing.

Script

Use scripts/cleanup.sh; do not recreate its parsing and guard logic ad hoc unless the repository layout makes it unusable.

Version History

  • 29fe043 Current 2026-08-20 18:33

Same Skill Collection

.agents/skills/add-provider-doc/SKILL.md
.agents/skills/add-setting-env/SKILL.md
.agents/skills/agent-runtime-hooks/SKILL.md
.agents/skills/agent-signal/SKILL.md
.agents/skills/agent-testing-bot/SKILL.md
.agents/skills/agent-tracing/SKILL.md
.agents/skills/agent-work/SKILL.md
.agents/skills/builtin-tool/SKILL.md
.agents/skills/chat-sdk/SKILL.md
.agents/skills/cli/SKILL.md
.agents/skills/data-fetching-architecture/SKILL.md
.agents/skills/db-migrations/SKILL.md
.agents/skills/debug-package/SKILL.md
.agents/skills/deep-review/SKILL.md
.agents/skills/design-prototype/SKILL.md
.agents/skills/desktop/SKILL.md
.agents/skills/docs-changelog/SKILL.md
.agents/skills/drizzle/SKILL.md
.agents/skills/heterogeneous-agent/SKILL.md
.agents/skills/hotkey/SKILL.md
.agents/skills/i18n/SKILL.md
.agents/skills/linear/SKILL.md
.agents/skills/llm-generation/SKILL.md
.agents/skills/modal/SKILL.md
.agents/skills/model-bank-metadata/SKILL.md
.agents/skills/product-design/SKILL.md
.agents/skills/project-overview/SKILL.md
.agents/skills/react/SKILL.md
.agents/skills/response-compliance/SKILL.md
.agents/skills/skills-audit/SKILL.md
.agents/skills/spa-routes/SKILL.md
.agents/skills/split-micro-app/SKILL.md
.agents/skills/store-data-structures/SKILL.md
.agents/skills/testing/SKILL.md
.agents/skills/trpc-router/SKILL.md
.agents/skills/typescript/SKILL.md
.agents/skills/upstash-workflow/SKILL.md
.agents/skills/ux-audit/SKILL.md
.agents/skills/ux/SKILL.md
.agents/skills/version-release/SKILL.md
.agents/skills/zustand/SKILL.md
.agents/skills/agent-testing/SKILL.md
.agents/skills/compose-atoms/SKILL.md
.agents/skills/debug-frontend-with-browser/SKILL.md
.agents/skills/pr/SKILL.md
packages/builtin-skills/src/acceptance/SKILL.md

Metadata

Files
0
Version
a06b4e2
Hash
2091b0b5
Indexed
2026-08-20 18:33

Главная - Вики-сайт
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-08-31 02:06
浙ICP备14020137号-1 $Гость$