using-git-worktrees by sickn33/antigravity-awesome-skills
npx skills add https://github.com/sickn33/antigravity-awesome-skills --skill using-git-worktreesGit worktrees 创建共享同一仓库的独立工作空间,允许同时处理多个分支而无需切换。
核心原则: 系统化目录选择 + 安全检查 = 可靠的隔离。
开始时声明: "我正在使用 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 中没有偏好设置:
未找到 worktree 目录。我应该在何处创建 worktrees?
1. .worktrees/(项目本地,隐藏)
2. ~/.config/superpowers/worktrees/<project-name>/(全局位置)
您倾向于哪个?
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
在创建 worktree 之前必须验证目录是否被忽略:
# 检查目录是否被忽略(尊重本地、全局和系统 gitignore)
git check-ignore -q .worktrees 2>/dev/null || git check-ignore -q worktrees 2>/dev/null
如果未被忽略:
根据 Jesse 的规则"立即修复损坏的东西":
为何关键: 防止意外将 worktree 内容提交到仓库。
无需 .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
# 使用新分支创建 worktree
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
运行测试以确保 worktree 从干净状态开始:
# 示例 - 使用适合项目的命令
npm test
cargo test
pytest
go test ./...
如果测试失败: 报告失败,询问是继续还是调查。
如果测试通过: 报告准备就绪。
Worktree 准备就绪于 <full-path>
测试通过(<N> 个测试,0 个失败)
准备实现 <feature-name>
| 情况 | 操作 |
|---|---|
.worktrees/ 存在 | 使用它(验证是否被忽略) |
worktrees/ 存在 | 使用它(验证是否被忽略) |
| 两者都存在 | 使用 .worktrees/ |
| 都不存在 | 检查 CLAUDE.md → 询问用户 |
| 目录未被忽略 | 添加到 .gitignore + 提交 |
| 基线测试失败 | 报告失败 + 询问 |
| 没有 package.json/Cargo.toml | 跳过依赖安装 |
git check-ignoreYou: 我正在使用 using-git-worktrees 技能来设置一个独立的工作空间。
[检查 .worktrees/ - 存在]
[验证忽略 - git check-ignore 确认 .worktrees/ 被忽略]
[创建 worktree: git worktree add .worktrees/auth -b feature/auth]
[运行 npm install]
[运行 npm test - 47 个通过]
Worktree 准备就绪于 /Users/jesse/myproject/.worktrees/auth
测试通过(47 个测试,0 个失败)
准备实现 auth 功能
绝不:
始终:
由以下调用:
与以下配合使用:
此技能适用于执行概述中描述的工作流或操作。
每周安装量
270
仓库
GitHub 星标数
27.1K
首次出现
2026年1月19日
安全审计
安装于
claude-code230
opencode199
gemini-cli196
antigravity187
codex170
cursor169
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:
This skill is applicable to execute the workflow or actions described in the overview.
Weekly Installs
270
Repository
GitHub Stars
27.1K
First Seen
Jan 19, 2026
Security Audits
Gen Agent Trust HubWarnSocketPassSnykPass
Installed on
claude-code230
opencode199
gemini-cli196
antigravity187
codex170
cursor169
agent-browser 浏览器自动化工具 - Vercel Labs 命令行网页操作与测试
140,500 周安装