一键导入
using-git-worktrees
当确实需要与当前工作区隔离时使用,例如并行开发、临时 hotfix、PR 检查、多方案实验或执行大型实现计划。不要作为日常小修、普通 bug 修复、只读调查或单文件改动的默认流程。
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
当确实需要与当前工作区隔离时使用,例如并行开发、临时 hotfix、PR 检查、多方案实验或执行大型实现计划。不要作为日常小修、普通 bug 修复、只读调查或单文件改动的默认流程。
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Use this skill when the task is specifically about AI search, AI Overviews, LLM citations, answer-engine optimization, or improving visibility in AI-generated answers. Good fit for AEO, GEO, LLMO, AI citations, zero-click AI visibility, and optimization for ChatGPT, Perplexity, Claude, Gemini, or similar systems. Do NOT use as the default for broad SEO audits or for pure schema implementation.
在创造性产品或设计工作之前使用此技能:创建新功能、构建新组件、添加新能力,或有意改变既定产品行为。在实现前先探索用户意图、需求和设计。不要用于 bug 修复、测试失败、构建失败、回归修复、恢复已有行为,或预期行为已经明确的实现任务;这些情况优先使用 systematic-debugging、test-driven-development 和 verification-before-completion。
Unified Impeccable frontend design skill. Use when the goal is to design, build, redesign, or improve a frontend interface — web pages, landing pages, dashboards, product UI, app shells, components, forms, settings, onboarding, empty states, responsive behavior, typography, spacing, layout, color, motion, UX copy, accessibility, or UI-perceived performance. Also use for Impeccable command-style requests aimed at frontend work, such as `impeccable craft`, `shape`, `init`, `document`, `extract`, `critique`, `audit`, `polish`, `bolder`, `quieter`, `distill`, `harden`, `onboard`, `animate`, `colorize`, `typeset`, `layout`, `delight`, `overdrive`, `clarify`, `adapt`, `optimize`, `live` (`teach` is only a deprecated alias for `init`). Do NOT use for backend or non-frontend code audits, docs, or reviews; live-site design-language extraction; static poster or cover art; HTML slide decks; PowerPoint / PDF / Word / spreadsheet deliverables; or specialized React/Next performance work.
遇到 bug、测试失败、构建失败、生产事故或异常行为时使用;在提出修复方案之前先找根因,不要凭直觉打补丁。 / Use for bugs, test failures, build failures, production incidents, or unexpected behavior — investigate the root cause before proposing a fix; do not patch symptoms.
在实现新功能、有意的行为变更,或非平凡 bug 修复时使用——先写一个会失败的测试,再写实现代码。例外:一次性原型、生成代码、配置文件、单行 trivial 修改、纯文案/排版/样式调整,以及没有可测行为的改动。 / Use when implementing new features, intentional behavior changes, or non-trivial bug fixes — write a failing test before implementation. Exceptions: throwaway prototypes, generated code, config files, trivial single-line patches, copy / typography / pure style edits, and changes with no testable behavior.
在宣称工作完成、已修复或测试通过之前使用,在提交或创建 PR 之前——必须运行验证命令并确认输出后才能声称成功;始终用证据支撑断言。 / Use before claiming work is complete, fixed, or tests pass, and before commit / PR — run verification commands and confirm output before stating success; back every claim with evidence.
| name | using-git-worktrees |
| description | 当确实需要与当前工作区隔离时使用,例如并行开发、临时 hotfix、PR 检查、多方案实验或执行大型实现计划。不要作为日常小修、普通 bug 修复、只读调查或单文件改动的默认流程。 |
| version | 1.0.0 |
| license | MIT |
| metadata | {"hermes":{"tags":["git","workflow"]}} |
Use this skill only when isolation is valuable, not as the default setup for ordinary work.
Trigger it when the task clearly involves one of these goals:
Do not trigger it for:
If the user did not ask for isolation and the task is small, work in the current workspace while respecting existing uncommitted changes.
If this skill references missing cleanup or execution skills, adapt the workflow to available OpenCode tools and normal git commands rather than blocking on unavailable skills.
确保工作发生在隔离的工作区中。优先使用你的平台的原生 worktree 工具。仅在没有原生工具可用时,再回退到手动 git worktree。
核心原则: 先检测现有隔离。然后用原生工具。再回退到 git。绝不与 harness 对抗。
开始时宣布: "我正在使用 using-git-worktrees 技能来建立一个隔离的工作区。"
创建任何东西之前,先检查你是否已经在一个隔离的工作区里。
GIT_DIR=$(cd "$(git rev-parse --git-dir)" 2>/dev/null && pwd -P)
GIT_COMMON=$(cd "$(git rev-parse --git-common-dir)" 2>/dev/null && pwd -P)
BRANCH=$(git branch --show-current)
Submodule 守卫: 在 git submodule 内 GIT_DIR != GIT_COMMON 也为真。在判定"已经在 worktree 内"之前,先确认你不在 submodule 里:
# 如果这条命令返回路径,说明你在 submodule 里,不是 worktree —— 按普通仓库处理
git rev-parse --show-superproject-working-tree 2>/dev/null
如果 GIT_DIR != GIT_COMMON(且不是 submodule): 你已经在一个 linked worktree 内。跳到步骤 2(项目设置)。不要再创建一个 worktree。
按分支状态报告:
<path>,分支 <name>。"<path>(分离 HEAD,由外部管理)。完成时需要创建分支。"如果 GIT_DIR == GIT_COMMON(或在 submodule 内): 你在一个普通的仓库检出里。
用户是否已经在你的 instructions 里表明过 worktree 偏好?如果没有,创建 worktree 之前先征求同意:
"你希望我搭一个隔离的 worktree 吗?它能保护你当前分支不被改动。"
如果用户已声明过偏好,直接遵循,不再询问。如果用户拒绝同意,原地工作并跳到步骤 2。
你有两种机制。按这个顺序尝试。
用户已经请求隔离工作区(步骤 0 已获同意)。你是否已经有创建 worktree 的方法?可能是名为 EnterWorktree、WorktreeCreate 的工具、/worktree 命令,或 --worktree 标志。如果有,用它,然后跳到步骤 2。
原生工具自动处理目录放置、分支创建和清理。在你已经有原生工具的情况下使用 git worktree add,会创建你的 harness 看不到也无法管理的"幻影状态"。
只有在没有原生 worktree 工具可用时,才进入步骤 1b。
只在步骤 1a 不适用时使用 —— 你没有可用的原生 worktree 工具。手动用 git 创建 worktree。
按以下优先级。明确的用户偏好始终优先于观察到的文件系统状态。
检查你的 instructions 里是否声明过 worktree 目录偏好。 如果用户已指定,不再询问直接用。
检查是否存在项目本地的 worktree 目录:
ls -d .worktrees 2>/dev/null # 首选(隐藏目录)
ls -d worktrees 2>/dev/null # 备选
找到就用。如果两者都存在,.worktrees 优先。
如果没有其他可参考的信息,默认用项目根目录下的 .worktrees/。
创建 worktree 前必须验证目录已被忽略:
git check-ignore -q .worktrees 2>/dev/null || git check-ignore -q worktrees 2>/dev/null
如果未被忽略: 添加到 .gitignore,提交该改动,然后继续。
为什么关键: 防止 worktree 内容被意外提交到仓库。
# 根据选定位置确定路径
path="$LOCATION/$BRANCH_NAME"
git worktree add "$path" -b "$BRANCH_NAME"
cd "$path"
沙盒回退: 如果 git worktree add 因权限错误(沙盒拒绝)失败,告诉用户沙盒阻止了 worktree 创建,你将在当前目录原地工作。然后原地运行 setup 和基线测试。
自动检测并运行相应的设置命令:
# Node.js
if [ -f package.json ]; then npm install; fi
# Rust
if [ -f Cargo.toml ]; then cargo build; fi
# Python
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
if [ -f pyproject.toml ]; then poetry install; fi
# Go
if [ -f go.mod ]; then go mod download; fi
运行测试确保工作区初始状态干净:
# 使用项目对应的命令
npm test / cargo test / pytest / go test ./...
如果测试失败: 报告失败,询问是继续还是排查。
如果测试通过: 报告就绪。
工作树已就绪:<full-path>
测试通过(<N> 个测试,0 个失败)
准备实现 <feature-name>
| 情况 | 操作 |
|---|---|
| 已在 linked worktree 内 | 跳过创建(步骤 0) |
| 在 submodule 内 | 按普通仓库处理(步骤 0 守卫) |
| 有原生 worktree 工具 | 用它(步骤 1a) |
| 没有原生工具 | git worktree 回退(步骤 1b) |
.worktrees/ 存在 | 用它(验证已忽略) |
worktrees/ 存在 | 用它(验证已忽略) |
| 两者都存在 | 用 .worktrees/ |
| 都不存在 | 检查 instructions 文件,再默认 .worktrees/ |
| 目录未被忽略 | 添加到 .gitignore + 提交 |
| 创建时权限错误 | 沙盒回退,原地工作 |
| 基线测试失败 | 报告失败 + 询问 |
| 无 package.json/Cargo.toml | 跳过依赖安装 |
git worktree addgit check-ignore绝不:
EnterWorktree)的情况下还用 git worktree add。这是 #1 错误——有就用。始终:
被以下技能调用:
配合使用: