using-git-worktrees
当需要开始与当前工作区隔离的功能开发或执行实现计划之前使用——创建具有智能目录选择和安全验证的隔离 git 工作树
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
Menu
当需要开始与当前工作区隔离的功能开发或执行实现计划之前使用——创建具有智能目录选择和安全验证的隔离 git 工作树
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
Based on SOC occupation classification
CodingHub 工具广场操作指南。当用户要求搜索/安装/发布/更新 CodingHub 工具,发帖到论坛,管理知识库,或与 CodingHub 平台交互时使用。支持双通道:MCP 优先,HTTP 直连自动降级(Python 或 Node.js CJS CLI 封装,跨平台)。
使用 CodeWiki-CN MCP 工具为代码仓库生成 Wiki 文档并管理 LLM Wiki 知识库。支持三层增强模式:codebase-memory-mcp(深度增强:Leiden 聚类、Cypher 查询、跨服务追踪、复杂度分析)、CodeGraph(调用图增强)、或纯 CodeWiki(标准模式)。自动检测可用 MCP 服务器并选择最优模式。当用户要求生成 Wiki、代码文档、仓库文档、分析代码库结构时使用。
UI/UX design intelligence with searchable database
Use when building and packaging the project for deployment, including frontend build, backend JAR, and creating distribution zip
中文 review 沟通参考——话术模板、分级标注(必须修复/建议修改/仅供参考)、国内团队常见反模式应对。仅在用户显式 /chinese-code-review 时调用,不要根据上下文自动触发。
中文 commit 与 changelog 配置参考——Conventional Commits 中文适配、commitlint/husky/commitizen 中文模板、conventional-changelog 中文配置。仅在用户显式 /chinese-commit-conventions 时调用,不要根据上下文自动触发。
| name | using-git-worktrees |
| description | 当需要开始与当前工作区隔离的功能开发或执行实现计划之前使用——创建具有智能目录选择和安全验证的隔离 git 工作树 |
| allowed-tools | null |
| disable | true |
Git 工作树创建共享同一仓库的隔离工作区,允许同时在多个分支上工作而无需切换。
核心原则: 系统化的目录选择 + 安全验证 = 可靠的隔离。
开始时宣布: "我正在使用 using-git-worktrees 技能来建立一个隔离的工作区。"
按以下优先顺序执行:
# 按优先顺序检查
ls -d .worktrees 2>/dev/null # 首选(隐藏目录)
ls -d worktrees 2>/dev/null # 备选
如果找到: 使用该目录。如果两者都存在,.worktrees 优先。
grep -i "worktree.*director" CLAUDE.md 2>/dev/null
如果指定了偏好: 直接使用,无需询问。
如果没有现有目录且 CLAUDE.md 中无偏好设置:
未找到工作树目录。我应该在哪里创建工作树?
1. .worktrees/(项目本地,隐藏目录)
2. ~/.config/superpowers/worktrees/<project-name>/(全局位置)
你倾向哪个?
创建工作树前必须验证目录已被忽略:
# 检查目录是否被忽略(遵循本地、全局和系统 gitignore)
git check-ignore -q .worktrees 2>/dev/null || git check-ignore -q worktrees 2>/dev/null
如果未被忽略:
根据 Jesse 的规则"立即修复坏掉的东西":
为什么这很关键: 防止意外将工作树内容提交到仓库。
无需 .gitignore 验证——完全在项目之外。
project=$(basename "$(git rev-parse --show-toplevel)")
# 确定完整路径
case $LOCATION in
.worktrees|worktrees)
path="$LOCATION/$BRANCH_NAME"
;;
~/.config/superpowers/worktrees/*)
path="~/.config/superpowers/worktrees/$project/$BRANCH_NAME"
;;
esac
# 创建带有新分支的工作树
git worktree add "$path" -b "$BRANCH_NAME"
cd "$path"
自动检测并运行相应的设置命令:
# 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>
| 情况 | 操作 |
|---|---|
.worktrees/ 存在 | 使用它(验证已忽略) |
worktrees/ 存在 | 使用它(验证已忽略) |
| 两者都存在 | 使用 .worktrees/ |
| 都不存在 | 检查 CLAUDE.md → 询问用户 |
| 目录未被忽略 | 添加到 .gitignore + 提交 |
| 基线测试失败 | 报告失败 + 询问 |
| 无 package.json/Cargo.toml | 跳过依赖安装 |
git check-ignore你:我正在使用 using-git-worktrees 技能来建立一个隔离的工作区。
[检查 .worktrees/ - 存在]
[验证已忽略 - git check-ignore 确认 .worktrees/ 已被忽略]
[创建工作树:git worktree add .worktrees/auth -b feature/auth]
[运行 npm install]
[运行 npm test - 47 个通过]
工作树已就绪:/Users/jesse/myproject/.worktrees/auth
测试通过(47 个测试,0 个失败)
准备实现 auth 功能
绝不:
始终:
被以下技能调用:
配合使用: