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

using-git-worktrees

为功能开发准备独立工作区,先检查是否已隔离,再使用环境内置功能或 git worktree 创建,并完成依赖准备和修改前的测试。

原文查看原文说明

Use when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallback

AI 评分90分/ 100查看安装方法

适用场景

  • 在独立工作区开始功能开发
  • 执行实施计划前准备环境
  • 检查当前工作区是否已隔离
  • 确认修改前的测试状态

中文介绍

功能

为功能开发准备独立工作区。先检查当前是否已处于隔离的工作区,必要时使用运行环境内置的创建功能。如果没有此功能,则使用 git worktree,让不同分支拥有各自的工作目录。流程包括选择保存位置、确认目录已被排除在 Git 跟踪之外、准备依赖,以及开始实施前运行测试。

适用场景

适合希望在当前工作位置之外开发新功能,或即将执行实施计划的情况。检查现有隔离状态可以避免重复创建工作区,修改前运行测试则能确认哪些失败原本就已存在。

使用示例

  • “请为这个功能准备一个独立工作区。”
  • “请在执行实施计划前,检查依赖和测试状态。”

注意事项

手动创建需要 Git。若用户尚未指定创建偏好,会先征求同意;用户拒绝时,继续在当前目录工作。对于项目内的保存位置,会检查排除设置,若未设置,则更新并提交 .gitignore。如果权限阻止创建工作区,则继续在当前目录完成准备。

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

客观评估

AI 仅根据 SKILL.md 的内容,从 4 个方面进行了评估。星标数和热度不计入评估。

指令清晰度能否看出何时使用、做什么
A良好明确在功能开发或执行实施计划前,检查隔离状态并准备工作区。
步骤具体性步骤、输入输出和示例是否具体
A良好提供 git rev-parse 检查、创建命令、依赖准备、测试及报告格式。
安全性发送数据、删除文件、执行命令等是否有说明
B部分不足要求创建前同意并检查忽略设置,但安装依赖和自动提交没有单独确认步骤。
安装难易度所需工具和 API 密钥是否少且有说明
A良好说明如何选择环境内置功能或 Git,并提供各语言的依赖准备命令。

总分按每项 A=25 分、B=15 分、C=5 分相加。 由 AI(OpenAI Codex)于 2026年10月19日 评估。仅供参考,安装前请同时查看原文。

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

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

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

包含的文件(1)

  • SKILL.md6.7 KB

SKILL.md(原文)

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

Using Git Worktrees

Overview

Ensure work happens in an isolated workspace. Prefer your platform's native worktree tools. Fall back to manual git worktrees only when no native tool is available.

Core principle: Detect existing isolation first. Then use native tools. Then fall back to git. Never fight the harness.

Announce at start: "I'm using the using-git-worktrees skill to set up an isolated workspace."

Step 0: Detect Existing Isolation

Before creating anything, check if you are already in an isolated workspace.

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 guard: GIT_DIR != GIT_COMMON is also true inside git submodules. Before concluding "already in a worktree," verify you are not in a submodule:

# If this returns a path, you're in a submodule, not a worktree — treat as normal repo
git rev-parse --show-superproject-working-tree 2>/dev/null

If GIT_DIR != GIT_COMMON (and not a submodule): You are already in a linked worktree. Skip to Step 2 (Project Setup). Do NOT create another worktree.

Report with branch state:

  • On a branch: "Already in isolated workspace at <path> on branch <name>."
  • Detached HEAD: "Already in isolated workspace at <path> (detached HEAD, externally managed). Branch creation needed at finish time."

If GIT_DIR == GIT_COMMON (or in a submodule): You are in a normal repo checkout.

Has the user already indicated their worktree preference in your instructions? If not, ask for consent before creating a worktree:

"Would you like me to set up an isolated worktree? It protects your current branch from changes."

Honor any existing declared preference without asking. If the user declines consent, work in place and skip to Step 2.

Step 1: Create Isolated Workspace

You have two mechanisms. Try them in this order.

1a. Native Worktree Tools (preferred)

The user has asked for an isolated workspace (Step 0 consent). Do you already have a way to create a worktree? It might be a tool with a name like EnterWorktree, WorktreeCreate, a /worktree command, or a --worktree flag. If you do, use it and skip to Step 2.

Native tools handle directory placement, branch creation, and cleanup automatically. Using git worktree add when you have a native tool creates phantom state your harness can't see or manage.

Only proceed to Step 1b if you have no native worktree tool available.

1b. Git Worktree Fallback

Only use this if Step 1a does not apply — you have no native worktree tool available. Create a worktree manually using git.

Directory Selection

Follow this priority order. Explicit user preference always beats observed filesystem state.

  1. Check your instructions for a declared worktree directory preference. If the user has already specified one, use it without asking.

  2. Check for an existing project-local worktree directory:

    ls -d .worktrees 2>/dev/null     # Preferred (hidden)
    ls -d worktrees 2>/dev/null      # Alternative
    

    If found, use it. If both exist, .worktrees wins.

  3. If there is no other guidance available, default to .worktrees/ at the project root.

Safety Verification (project-local directories only)

MUST verify directory is ignored before creating worktree:

git check-ignore -q .worktrees 2>/dev/null || git check-ignore -q worktrees 2>/dev/null

If NOT ignored: Add to .gitignore, commit the change, then proceed.

Why critical: Prevents accidentally committing worktree contents to repository.

Create the Worktree

# Determine path based on chosen location
path="$LOCATION/$BRANCH_NAME"

git worktree add "$path" -b "$BRANCH_NAME"
cd "$path"

Sandbox fallback: If git worktree add fails with a permission error (sandbox denial), tell the user the sandbox blocked worktree creation and you're working in the current directory instead. Then run setup and baseline tests in place.

Step 2: Project Setup

Auto-detect and run appropriate 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

Step 3: Verify Clean Baseline

Run tests to ensure workspace starts clean:

# Use project-appropriate command
npm test / cargo test / pytest / go test ./...

If tests fail: Report failures, ask whether to proceed or investigate.

If tests pass: Report ready.

Report

Worktree ready at <full-path>
Tests passing (<N> tests, 0 failures)
Ready to implement <feature-name>

Quick Reference

SituationAction
Already in linked worktreeSkip creation (Step 0)
In a submoduleTreat as normal repo (Step 0 guard)
Native worktree tool availableUse it (Step 1a)
No native toolGit worktree fallback (Step 1b)
.worktrees/ existsUse it (verify ignored)
worktrees/ existsUse it (verify ignored)
Both existUse .worktrees/
Neither existsCheck instruction file, then default .worktrees/
Directory not ignoredAdd to .gitignore + commit
Permission error on createSandbox fallback, work in place
Tests fail during baselineReport failures + ask
No package.json/Cargo.tomlSkip dependency install

Common Rationalizations

ExcuseReality
"I'm obviously not in a worktree — no need to check"Run Step 0. Harness-created isolation and submodules both fool eyeballing; the detection commands settle it.
"git worktree add is quicker than hunting for a native tool"A native tool (e.g. EnterWorktree) owns placement, branching, and cleanup. Bypassing it is the #1 mistake — it creates phantom state your harness can't see or manage.
"The worktree directory is surely ignored already"Run git check-ignore. An unignored worktree directory commits the whole tree into the repo.
"Any directory name works"Explicit instructions beat an existing project-local directory, which beats the .worktrees/ default.
"The workspace is fresh — baseline tests can wait"A dirty baseline makes every later failure ambiguous. Run the tests now; proceeding past failures is your human partner's call.

评价

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

评论

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

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

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

0 / 1000 字

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

同一仓库的技能

brainstorming

免费有简介AI 评分 90分

在开始新功能或项目之前,通过对话明确目的、偏好和限制。根据需要用图示或原型核对理解,并按工作规模整理说明或设计文档。

  • 明确新功能的目的
  • 整理演讲或商业构想
  • 比较界面或房间布局
obra/superpowers30.2万2026年10月10日 更新

diagnosing-superpowers

免费有简介AI 评分 90分

读取 superpowers 会话记录,调查重复工作、偏离计划、耗时及令牌消耗。以文件路径和行号为依据整理经过,生成有证据支持的报告。

  • 调查重复工作或偏离计划的情况
  • 查看会话耗时和令牌消耗
  • 确认技能是否被使用
obra/superpowers30.2万2026年10月10日 更新

dispatching-parallel-agents

免费有简介AI 评分 90分

将相互独立的缺陷或测试失败分配给不同代理,并行调查和修复。明确各自范围与报告要求,再检查修改冲突、运行完整测试并整合结果。

  • 调查原因互不相关的测试失败
  • 修复不同功能中的独立缺陷
  • 明确多个代理的工作范围
obra/superpowers30.2万2026年10月10日 更新

executing-plans

免费有简介AI 评分 90分

在同一会话中逐项执行已有的实施计划,确认测试先失败后通过,记录进度与判断,并在全部任务结束后审查整个分支的更改。

  • 执行已有的开发计划
  • 不另派实施代理完成工作
  • 根据进度记录恢复任务
obra/superpowers30.2万2026年10月10日 更新

finishing-a-development-branch

免费有简介AI 评分 90分

在实现完成后检查全部测试,让用户选择本地合并、创建拉取请求或保留现状,并执行所选操作,再根据选择和工作环境整理分支与工作区。

  • 在本地合并已完成的功能
  • 推送分支并创建拉取请求
  • 保留已完成的修改以便日后整合
obra/superpowers30.2万2026年10月10日 更新

receiving-code-review

免费有简介AI 评分 80分

将代码审查意见与实际代码、支持的运行环境及现有行为进行核对,确认建议是否合理,梳理疑问并依据技术证据回复,再逐项修改和测试。

  • 梳理含糊的代码审查意见
  • 核实建议修改的兼容性
  • 检查拟扩展的功能是否实际使用
obra/superpowers30.2万2026年10月10日 更新

查看 obra 的全部技能

报告此技能的问题