清理长时间未使用的 git worktree(GitHub 版)。仅在用户明确要求清理 worktree 时使用,不自动触发。 关键词:清理 worktree、删除 worktree、移除旧分支、worktree 回收。
64
76%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
View guide
Passed
No findings from the security scan
Fix and improve this skill with Tessl
tessl review fix ./ai/skills/cleanup-github-worktree/SKILL.md手动触发:当用户明确要求清理、删除或回收长时间未使用的 worktree 时执行。
必须在 master 上执行:执行前 git branch --show-current;若不是 master,中止并提示用户切换。
使用 AskQuestion 让用户选择阈值:
选择清理阈值:超过多久未使用的 worktree 将被清理?1 周(对应 7 天)2 周(对应 14 天)1 个月(对应 30 天)将用户选择映射为天数:
| 选项 | 天数 |
|---|---|
| 1 周 | 7 |
| 2 周 | 14 |
| 1 个月 | 30 |
运行清理脚本,输出候选分支名列表(每行一个分支名),不执行删除。
根据操作系统选择脚本(通过用户信息中的 OS Version 判断):
Windows(PowerShell):
powershell -File .cursor/skills/cleanup-github-worktree/scripts/cleanup-worktree.ps1 -Days <天数>macOS / Linux(Bash):
bash .cursor/skills/cleanup-github-worktree/scripts/cleanup-worktree.sh -d <天数>将脚本输出的分支名列表展示给用户。如果没有找到过期 worktree,告知用户并结束。
使用 AskQuestion 让用户确认是否继续:
以上 <N> 个 worktree 将被清理(关闭 GitHub Issue、移除 worktree、删除本地分支),是否继续?确认清理取消用户选择取消时,结束工作流。
对 Step 2 识别出的每一个候选分支,以该分支名作为目标分支,执行 close-github-worktree-done skill 的 Step 1 ~ Step 5 完整流程(跳过其 Step 0 的交互选择)。
open 状态执行关闭(state=closed, state_reason=completed),无需逐个再次 AskQuestion;已 closed 的跳过。close-github-worktree-done Step 2 规则跳过,在最终报告中标记为"跳过(有未提交变更)"。向用户展示清理结果摘要,包含每个分支的处理状态:
| 分支名 | GitHub Issue | worktree | 本地分支 | 备注 |
|---|---|---|---|---|
| bug-12994 | ✅ closed | ✅ 已移除 | ✅ 已删除 | |
| feat-11524 | ⏭ 跳过 | ✅ 已移除 | ✅ 已删除 | 分支名无 issue 号 |
| pref-12948 | — | — | — | 跳过(有未提交变更) |
| 脚本 | 系统 | 路径 |
|---|---|---|
| cleanup-worktree.ps1 | Windows | .cursor/skills/cleanup-github-worktree/scripts/cleanup-worktree.ps1 |
| cleanup-worktree.sh | macOS/Linux | .cursor/skills/cleanup-github-worktree/scripts/cleanup-worktree.sh |
脚本职责:
git worktree list --porcelain 获取所有 worktreegit log -1 --format=%ct <branch> 获取分支最后一次 commit 时间;detached HEAD 时回退到目录修改时间94743cb
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.