using-git-worktrees by davila7/claude-code-templates
npx skills add https://github.com/davila7/claude-code-templates --skill using-git-worktreesGit 工作树创建共享同一仓库的独立工作空间,允许在不切换分支的情况下同时处理多个分支。
核心原则: 系统化目录选择 + 安全验证 = 可靠的隔离。
开始时声明: "我正在使用 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/<项目名称>/ (全局位置)
您倾向于哪个选项?
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
在创建工作树之前,必须验证目录是否被忽略:
# 检查目录是否被忽略(尊重本地、全局和系统的 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 ./...
如果测试失败: 报告失败,询问是继续还是调查。
如果测试通过: 报告准备就绪。
工作树准备就绪,位于 <完整路径>
测试通过(<N> 个测试,0 个失败)
准备实现 <功能名称>
| 情况 | 操作 |
|---|---|
.worktrees/ 存在 | 使用它(验证是否被忽略) |
worktrees/ 存在 | 使用它(验证是否被忽略) |
| 两者都存在 | 使用 .worktrees/ |
| 都不存在 | 检查 CLAUDE.md → 询问用户 |
| 目录未被忽略 | 添加到 .gitignore + 提交 |
| 基线测试失败 | 报告失败 + 询问 |
| 无 package.json/Cargo.toml | 跳过依赖安装 |
git check-ignoreYou: I'm using the using-git-worktrees skill to set up an isolated workspace.
[Check .worktrees/ - exists]
[Verify ignored - git check-ignore confirms .worktrees/ is ignored]
[Create worktree: git worktree add .worktrees/auth -b feature/auth]
[Run npm install]
[Run npm test - 47 passing]
Worktree ready at /Users/jesse/myproject/.worktrees/auth
Tests passing (47 tests, 0 failures)
Ready to implement auth feature
切勿:
始终:
由以下调用:
与以下配合使用:
每周安装数
156
仓库
GitHub 星标数
23.4K
首次出现
2026年1月21日
安全审计
安装于
claude-code134
opencode124
gemini-cli121
cursor115
codex110
antigravity110
Git worktrees create isolated workspaces sharing the same repository, allowing work on multiple branches simultaneously without switching.
Core principle: Systematic directory selection + safety verification = reliable isolation.
Announce at start: "I'm using the using-git-worktrees skill to set up an isolated workspace."
Follow this priority order:
# Check in priority order
ls -d .worktrees 2>/dev/null # Preferred (hidden)
ls -d worktrees 2>/dev/null # Alternative
If found: Use that directory. If both exist, .worktrees wins.
grep -i "worktree.*director" CLAUDE.md 2>/dev/null
If preference specified: Use it without asking.
If no directory exists and no CLAUDE.md preference:
No worktree directory found. Where should I create worktrees?
1. .worktrees/ (project-local, hidden)
2. ~/.config/superpowers/worktrees/<project-name>/ (global location)
Which would you prefer?
MUST verify directory is ignored before creating worktree:
# Check if directory is ignored (respects local, global, and system gitignore)
git check-ignore -q .worktrees 2>/dev/null || git check-ignore -q worktrees 2>/dev/null
If NOT ignored:
Per Jesse's rule "Fix broken things immediately":
Why critical: Prevents accidentally committing worktree contents to repository.
No .gitignore verification needed - outside project entirely.
project=$(basename "$(git rev-parse --show-toplevel)")
# Determine full path
case $LOCATION in
.worktrees|worktrees)
path="$LOCATION/$BRANCH_NAME"
;;
~/.config/superpowers/worktrees/*)
path="~/.config/superpowers/worktrees/$project/$BRANCH_NAME"
;;
esac
# Create worktree with new branch
git worktree add "$path" -b "$BRANCH_NAME"
cd "$path"
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
Run tests to ensure worktree starts clean:
# Examples - 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.
Worktree ready at <full-path>
Tests passing (<N> tests, 0 failures)
Ready to implement <feature-name>
| Situation | Action |
|---|---|
.worktrees/ exists | Use it (verify ignored) |
worktrees/ exists | Use it (verify ignored) |
| Both exist | Use .worktrees/ |
| Neither exists | Check CLAUDE.md → Ask user |
| Directory not ignored | Add to .gitignore + commit |
| Tests fail during baseline | Report failures + ask |
| No package.json/Cargo.toml | Skip dependency install |
git check-ignore before creating project-local worktreeYou: I'm using the using-git-worktrees skill to set up an isolated workspace.
[Check .worktrees/ - exists]
[Verify ignored - git check-ignore confirms .worktrees/ is ignored]
[Create worktree: git worktree add .worktrees/auth -b feature/auth]
[Run npm install]
[Run npm test - 47 passing]
Worktree ready at /Users/jesse/myproject/.worktrees/auth
Tests passing (47 tests, 0 failures)
Ready to implement auth feature
Never:
Always:
Called by:
Pairs with:
Weekly Installs
156
Repository
GitHub Stars
23.4K
First Seen
Jan 21, 2026
Security Audits
Gen Agent Trust HubWarnSocketPassSnykWarn
Installed on
claude-code134
opencode124
gemini-cli121
cursor115
codex110
antigravity110
agent-browser 浏览器自动化工具 - Vercel Labs 命令行网页操作与测试
152,900 周安装
Angular HTTP 数据获取教程:基于信号的 httpResource() 与 resource() 使用指南
1 周安装
Angular路由配置指南:v20+懒加载、函数式守卫与信号参数详解
1 周安装
iOS数据持久化与数据库路由指南:SwiftData、Core Data、CloudKit、迁移与审计
154 周安装
Angular CLI 工具集完整指南:v20+ 项目创建、代码生成与构建优化
1 周安装
Codex Wrapped 报告生成技能 - 获取过去30天和7天的Codex使用数据洞察
1 周安装
DOCX文档处理技能:专业格式编辑、视觉布局审阅与自动化渲染指南
1 周安装