.claude/skills/openspec-sp-git-worktree/SKILL.md
Git worktree 隔离工作空间管理。Use before starting implementation to create isolated workspace.
npx skillsauth add cenmiao/openspec-pro openspec-sp-git-worktreeInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
核心原则: Systematic directory selection + safety verification = reliable isolation
Git worktree 允许你同时在多个分支上工作,每个 worktree 有独立的 working directory。
project-root/
├── .git/
├── worktrees/
│ ├── feature-auth/ (branch: feature-auth)
│ ├── feature-api/ (branch: feature-api)
│ └── bugfix-login/ (branch: bugfix-login)
└── ...
┌─────────────────────────────────────────────────────────┐
│ Git Worktree Setup Process │
├─────────────────────────────────────────────────────────┤
│ │
│ 1. 目录选择 │
│ ┌─────────────────────────────────────┐ │
│ │ 1. 检查 .worktrees/ 或 worktrees/ │ │
│ │ 2. 检查 CLAUDE.md 偏好 │ │
│ │ 3. 询问用户 │ │
│ └─────────────────────────────────────┘ │
│ │ │
│ ▼ │
│ 2. 安全验证(必须) │
│ ┌─────────────────────────────────────┐ │
│ │ git check-ignore <directory> │ │
│ │ 如果被忽略 → 继续 │ │
│ │ 如果未被忽略 → 添加到.gitignore │ │
│ └─────────────────────────────────────┘ │
│ │ │
│ ▼ │
│ 3. 创建 Worktree │
│ git worktree add "<path>" -b "<branch>" │
│ │
│ 4. 项目 Setup │
│ npm install / cargo build / etc. │
│ │
│ 5. 基线测试验证 │
│ 运行测试确认环境正常 │
│ │
│ 6. 报告位置 │
│ "Worktree ready at <full-path>" │
│ │
└─────────────────────────────────────────────────────────┘
优先级顺序:
检查已有目录
.worktrees/ 是否存在worktrees/ 是否存在检查 CLAUDE.md 偏好
CLAUDE.md 或 .claude.md询问用户
验证工作目录是否被 git ignore:
git check-ignore <worktree-path>
如果被忽略: ✅ 继续
如果未被忽略:
# 添加到 .gitignore
echo "worktrees/" >> .gitignore
git add .gitignore
git commit -m "Ignore worktrees directory"
Jesse 规则: Fix broken things immediately. 如果 .gitignore 缺失,立即修复。
git worktree add "<full-path>" -b "<branch-name>"
分支命名:
feature/<name>bugfix/<name>experiment/<name>根据项目类型运行 setup:
# Node.js
npm install
# Python
pip install -r requirements.txt
# Rust
cargo build
# Go
go mod download
运行项目测试确认环境正常:
# Node.js
npm test
# Python
pytest
# Rust
cargo test
必须确认: 基线测试通过,环境就绪。
Worktree ready at <full-path>
Branch: <branch-name>
Tests: <pass/fail>
# 列出所有 worktrees
git worktree list
# 创建新 worktree
git worktree add <path> -b <branch>
# 删除 worktree
git worktree remove <path>
# 清理已删除的 worktree 信息
git worktree prune
# 检查是否被 ignore
git check-ignore <path>
用户:我要开始实现用户认证功能
助手:我使用 openspec-sp-git-worktree 技能来创建隔离工作空间。
**Step 1: 目录选择**
- 检查存在的工作树目录...
- 发现 `worktrees/` 目录
**Step 2: 安全验证**
- 验证 `worktrees/feature-auth` 是否被 ignore...
- ✅ 已忽略
**Step 3: 创建 Worktree**
- 执行:git worktree add "D:/project/worktrees/feature-auth" -b "feature/auth"
**Step 4: 项目 Setup**
- 执行:npm install
**Step 5: 基线测试**
- 执行:npm test
- ✅ 所有测试通过
**Step 6: 报告**
Worktree ready at D:/project/worktrees/feature-auth
Branch: feature/auth
Tests: 42 passing
后果: worktree 可能被意外提交
正确做法: 总是先验证 git check-ignore
后果: 目录结构不一致,难以管理
正确做法: 按优先级选择,或询问用户
后果: 后续开发基于错误环境
正确做法: 修复基线测试后再继续
testing
Verify implementation matches change artifacts. Use when the user wants to validate that implementation is complete, correct, and coherent before archiving.
data-ai
Sync delta specs from a change to main specs. Use when the user wants to update main specs with changes from a delta spec, without archiving the change.
testing
完成前必须有验证证据。Proof precedes assertion. Use before reporting any task completion.
tools
TDD 红/绿/重构循环。铁律:先失败测试后实现。Use when implementing any new functionality.