跳到正文
cccskills
免费在 GitHub 公开中文介绍

cleanup-git-worktrees

审查 Git worktree 和本地分支,按合并、闲置等原因列出可清理项,并标出有修改或未推送提交的项目供检查。确认目标后可执行清理并再次审查结果。

原文查看原文说明

Use for stale-worktree, Git registration and branch audits. Managed removal uses the repo lifecycle.

lobehub/lobehub星标 83,504(GitHub 83,504 + cccskills 0)

实测评分 未实测

查看安装方法

适用场景

  • 整理长期闲置的 worktree
  • 检查已合并的分支
  • 保护未推送的工作
  • 确认清理后的状态

中文介绍

功能

此技能会审查 Git worktree 和本地分支,并按状态分为可删除候选项、需要人工检查的项目和受保护项目。审查内容包括合并状态、PR 状态、闲置天数、未推送的提交以及工作区改动,同时说明某项为何可以删除。查看候选项后,可指定目标执行清理,再次审查并报告删除结果和保留下来的工作。

适用场景

适合整理长期未使用的 worktree,或在 PR 合并后清理本地分支。它会把需要保留的工作与删除候选项分开,便于检查已修改的文件和未推送的提交。如果仓库还通过 worktree 管理服务或其他资源,也会提示可能需要使用专门的生命周期流程。

使用示例

  • “审查这个仓库的 worktree,并说明各项可删除或受保护的原因。”
  • “检查已合并的 PR 分支,把仍有未推送工作的分支单独列出。”
  • “清理我已确认的分支,并报告清理后的状态。”

注意事项

审查使用附带的 scripts/cleanup.sh。可以通过已完成认证的 gh CLI 查询 PR 状态。删除属于破坏性操作;如果没有明确指定目标,技能会先列出候选项并请求确认。它不会对已登记的 worktree 使用递归删除。若要删除损坏登记遗留的目录,必须指定路径并确认。

本介绍由 AI(OpenAI Codex)根据公开的 SKILL.md 撰写。准确的规格请查看下方原文。

文档检查

AI 根据 SKILL.md 的内容检查了需要注意的操作和使用前提。评分只依据实际运行的结果(实测对比)。

安全性发送数据、删除文件、执行命令等是否有说明
B部分不足通常要求先确认,但仓库策略也允许删除有改动的已合并或已关闭 PR 分支。
安装难易度所需工具和 API 密钥是否少且有说明
B部分不足需要附带脚本;查询 PR 状态需使用已认证的 `gh` CLI。

不计入评分。 由 AI(OpenAI Codex)于 2026年10月26日 评估。仅供参考,安装前请同时查看原文。

如果您认为评估有误,请申请复核

请写明哪一项有误以及原因。无需登录。我们会对照 SKILL.md 重新评估,并在此处更新结果。

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

包含的文件(3)

  • SKILL.md10.9 KB
  • agents/openai.yaml241 B
  • scripts/cleanup.sh11.4 KB

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

Cleanup Git Worktrees

Use the bundled script to make classification deterministic. Treat cleanup as a destructive action: audit first, show the exact candidates grouped by why they are deletable, and obtain one explicit approval before applying deletion unless the user's current request already names the exact targets. Aim for a single approval round-trip, not a per-item Q&A.

Workflow

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

    bash .agents/skills/cleanup-git-worktrees/scripts/cleanup.sh audit --fetch --gh --stale-days 15 --base origin/canary
    
    • --fetch: prune the remote first. Omit only when offline and say so.
    • --gh: look up each branch's PR (number, state, head SHA) with the gh CLI. This is what turns [gone] into a verified merge; use it whenever gh is authenticated. It costs roughly one second per branch, so run it in the background on large repos.
    • --stale-days N: mark clean branches idle longer than N days with nothing unpushed as candidate-stale. The repository default the user has approved is 15 days.
    • --noise REGEX: untracked paths that never count as dirt (default node_modules|\.goal-tracing/).
  2. Interpret classifications:

    ClassificationMeaningAction
    protected-branchmain, canary, or the base refnever
    protect-currentthe worktree running the commandnever
    protect-dirtytracked modifications, or untracked files outside the noise regexkeep; list the files
    candidate-mergedtip is an ancestor of the basedelete
    candidate-pr-mergedPR state MERGED and local tip == PR head SHAdelete
    candidate-pr-closedPR CLOSED and tip == PR head or nothing unpusheddelete
    candidate-goneupstream pruned and nothing unpusheddelete after confirming PR state
    candidate-staleolder than --stale-days, clean, nothing unpusheddelete
    review-pr-merged-aheadPR merged but local tip has extra commitscheck the extra commits by subject (below)
    review-gone-unpushedupstream pruned but local-only commits existkeep; deleting loses work
    review-no-upstreamno upstream, not mergedkeep unless the user names it
    review-detacheddetached HEAD worktreekeep; show its dirty files
    broken-registration(...)registration whose gitdir is gonesee below
    activeeverything elsekeep

    Columns worth reading: dirty (real dirt), noise (ignorable untracked), age_days, unpushed (commits no remote ref reaches), pr / pr_state / tip_eq_pr.

  3. Present one compact table split into three groups: deletable now (all candidate-*), needs a manual check (review-*), and protected. Keep candidate-merged separate from candidate-gone, and never describe [gone] alone as proof of merge.

  4. After approval, use the repository's worktree lifecycle workflow when it manages services or other resources alongside a checkout; the Git-only script does not tear those down. For plain Git worktrees, pass exact branch names and the same classification flags used for the audit:

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

    Without --apply, cleanup is a dry run. The script re-classifies every target immediately before deletion and refuses anything that is not candidate-*. Worktrees whose only dirt is noise are removed with git worktree remove --force; everything else uses the plain, refusing form.

    Removing a worktree that still holds node_modules can take several minutes each. Run large batches in the background and report progress rather than waiting on a single foreground call.

  5. Run the audit again and report:

    • removed worktrees and branches, with the SHA each branch pointed at (the script prints it; reflog keeps it for 90 days);
    • retained dirty / unpushed / detached targets and why;
    • remaining worktree and local-branch counts;
    • any partial deletion or Git error.

Proving a merge

Squash and rebase merges leave no ancestry, so git merge-base --is-ancestor and git cherry say "not merged" for branches whose PR landed. Use this ladder instead:

  1. --gh reports pr_state=MERGED and tip_eq_pr=eq: the local tip is exactly what GitHub merged. Done.
  2. review-pr-merged-ahead (tip moved past the PR head): list the extra commits with git log <pr-head>..<branch> and search the base for each subject: git log origin/canary --oneline -F --grep="<subject>". A hit on the PR's squash commit means the commit was part of the PR. A miss means the commit is unmerged; check which live branch still contains it with git branch --contains <sha> before deleting.
  3. Branches named after a PR (pr-18412, codex/pr-18497-fix) are local review copies; verify the PR by number with gh pr view N --json state,headRefOid and compare subjects as above.
  4. Do not judge by git diff origin/canary <branch> -- <files>: on an old branch the diff is dominated by later changes on the base.

Zero unpushed means every local commit is reachable from some remote ref, so deleting the local branch loses nothing even when the PR is still OPEN; the user has approved deleting such branches once they pass the stale threshold.

Repo-approved deletion policy

The repository owner has approved the following for this repo, so a cleanup run does not need to re-ask per item. It is the sanctioned exception to the safety rules below; state it in the report and say plainly whenever uncommitted work is being discarded.

  • Dirt equal to the base is not dirt. A tracked file listed as modified whose content is byte-identical to the base (git diff --quiet <base> -- <file>) is stale residue of a branch that is simply behind. When presenting, do not count it as a real change: list such files in their own group so the genuine modifications stay visible.
  • Merged / closed PR branches are disposable together with their local commits. When a branch's PR is MERGED or CLOSED, its worktree and local branch may be removed even when unpushed > 0 or the tree is dirty. Record every branch SHA before deleting (reflog keeps them ~90 days) and state in the report that uncommitted edits are not recoverable.
  • Local scratch does not block removal. Untracked *.probe.test.ts, spike scripts under scripts/, and untracked screenshots (*.png) are disposable; do not raise them as blockers.
  • Still never delete: main, canary, the base ref, and the worktree running the command. A branch whose PR is OPEN is kept while it still holds local-only work (dirty files or unpushed > 0); a clean, fully-pushed branch with an open PR is the redundant local copy the stale rule already covers.

Proving a merge when the repo squash-merges. This repo squash-merges, so a landed PR leaves the squash commit on the base but none of the branch's own commits. Searching the base for an individual commit subject therefore fails for every squashed branch — do not read that as "unmerged". Decide review-pr-merged-ahead by the PR's state plus commit dates instead: if the branch tip is not newer than mergedAt, the branch is pure pre-merge history whose content is already on the base (verify the PR's mergeCommit with git merge-base --is-ancestor <mergeCommit> origin/canary). Only commits dated after mergedAt are candidate unmerged work — keep the branch and list them.

The bundled script still refuses anything outside candidate-*, so these removals are done manually: wt_path=$(git worktree list --porcelain …) → record git rev-parse <branch> → git worktree remove --force → git branch -D. Keep the run in the background; removals that hold node_modules take minutes each.

Broken registrations

git worktree list --porcelain marks an entry prunable when its gitdir file points nowhere (typically after a partial removal). The audit reports these as broken-registration(directory-present|missing; reason) instead of crashing on them.

  • git worktree prune drops only the registration. It never touches the directory or the branch, so it is safe to run before re-auditing.
  • A leftover directory has no .git, so its dirty state cannot be checked. Show its size and file count and ask before deleting it with rm -rf; that is the one place recursive deletion is acceptable, and only on a path the user named.

Safety rules

  • Never discard dirty worktrees merely because their branch is merged, [gone], or old; noise-only dirt (the --noise regex) does not count. The one exception is a worktree whose branch's PR is MERGED or CLOSED, per the repo-approved deletion policy above.
  • Never delete a branch with unpushed > 0 through this script; list it and let the user decide. Same exception: a MERGED/CLOSED PR branch may be removed under the owner's standing approval, with its SHA recorded first.
  • Never use recursive deletion on a registered worktree. If Git partially removes a directory, stop and inspect the exact path before deciding how to recover.
  • Never delete main, canary, or the base branch.
  • Preserve unrelated user changes and concurrent worktrees. The user's other sessions may be working in them.
  • When writing ad-hoc verification loops, run them under bash, not the interactive zsh: zsh does not word-split $var in for/argument positions, so file lists collapse into one argument and checks silently pass.

Script

Use scripts/cleanup.sh; do not recreate its parsing and guard logic ad hoc unless the repository layout makes it unusable. It is set -euo pipefail; helper functions that pipe through grep wrap it in || true so an empty match is "clean", not an abort.

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

acceptance

免费有简介

通过实际操作产品验证交付内容,记录用户可查看的证据,并发布验收报告。可检查已有验证计划或创建检查项,选择合适的操作界面,并使用 `lh` CLI 发布结果。

  • 实际检查更改后的产品行为
  • 收集截图或其他验证证据
  • 编写验证计划和报告
lobehub/lobehub8.4万2026年10月26日 更新

add-model-provider

免费有简介

本技能指导在 LobeHub 中接入 AI 模型提供商,涵盖运行时、模型信息、设置、品牌展示、文档和验收,并帮助判断新增模型是否需要新的提供商集成。

  • 为 LobeHub 接入新的 AI 模型提供商
  • 更新提供商设置说明或介绍
  • 判断添加模型是否需要新的提供商集成
lobehub/lobehub8.4万2026年10月26日 更新

add-setting-env

免费有简介

本技能指导如何用服务器端环境变量设置用户偏好默认值,涵盖变量校验、服务器配置、写入用户状态,以及更新 `.env.example` 和自托管文档。

  • 通过环境变量设置用户偏好默认值
  • 将设置接入服务器配置和用户状态
  • 更新环境变量示例及文档
lobehub/lobehub8.4万2026年10月26日 更新

agent-runtime-hooks

免费有简介

说明如何在智能体执行步骤、工具调用、人工审批、上下文压缩和子智能体调用时注册钩子。钩子可观察事件、模拟本地工具结果,也可通过 Webhook 按配置策略允许或拒绝工具调用。

  • 记录智能体步骤和错误
  • 测试时模拟工具结果
  • 通过 Webhook 允许或拒绝工具调用
lobehub/lobehub8.4万2026年10月26日 更新

agent-signal

免费有简介

此技能用于为智能体设计事件驱动的后台工作流,划分来源、信号、动作和策略的职责,并处理异步交接、去重、执行范围、完成记录与运行观测。

  • 添加事件触发的后台任务
  • 将工作移出对话请求
  • 防止动作重复执行
lobehub/lobehub8.4万2026年10月26日 更新

agent-testing-bot

免费有简介

本技能在 macOS 桌面聊天应用中测试机器人频道:打开应用、进入频道或联系人、发送消息、等待回复并截图。支持 Discord、Slack、Telegram、微信、飞书和 QQ;iMessage 使用 BlueBubbles 桥接。

  • 检查真实 Discord 频道中的机器人回复
  • 测试 Slack 或 Telegram 的对话流程
  • 记录 macOS 应用中的操作结果
lobehub/lobehub8.4万2026年10月26日 更新

查看 lobehub 的全部技能

报告此技能的问题