using-git-worktrees
Use when starting feature work that needs isolation from current workspace or before executing implementation plans - creates isolated git worktrees with smart directory selection and safety verification
- License 许可
- MIT
- 最近更新
- 2026-06-24
- Stars
- ★ 67
- Forks
- 24
01 前言 Front Matter
- name
- using-git-worktrees
- description
- Use when starting feature work that needs isolation from current workspace or before executing implementation plans - creates isolated git worktrees with smart directory selection and safety verification
02 资源文件 154
- 其他bin/find-browse814 B
- 其他bin/remote-slug572 B
- 参考文档PLAN-snapshot-dropdown-interactive.md4.5 KB
- 脚本scripts/build-node-server.sh2.2 KB
- 参考文档skill-report.json13.3 KB
- 其他SKILL.md.tmpl7.6 KB
- 脚本src/activity.ts6.4 KB
- 脚本src/audit.ts2.1 KB
- 脚本src/browse-client.ts11.0 KB
- 脚本src/browser-manager.ts55.4 KB
- 脚本src/browser-skill-commands.ts14.1 KB
- 脚本src/browser-skill-write.ts8.5 KB
- 脚本src/browser-skills.ts14.7 KB
- 脚本src/buffers.ts4.2 KB
- 脚本src/bun-polyfill.cjs2.9 KB
- 脚本src/cdp-allowlist.ts7.1 KB
- 脚本src/cdp-bridge.ts4.5 KB
- 脚本src/cdp-commands.ts2.5 KB
- 脚本src/cdp-inspector.ts25.8 KB
- 脚本src/claude-bin.ts2.7 KB
- 脚本src/cli.ts38.6 KB
- 脚本src/commands.ts21.2 KB
- 脚本src/config.ts4.7 KB
- 脚本src/content-security.ts11.5 KB
- 脚本src/cookie-import-browser.ts38.3 KB
- 脚本src/cookie-picker-routes.ts13.0 KB
- 脚本src/cookie-picker-ui.ts21.8 KB
- 脚本src/domain-skill-commands.ts11.5 KB
- 脚本src/domain-skills.ts15.4 KB
- 脚本src/error-handling.ts1.8 KB
- 脚本src/find-browse.ts2.2 KB
- 脚本src/media-extract.ts5.2 KB
- 脚本src/meta-commands.ts46.7 KB
- 脚本src/network-capture.ts5.1 KB
- 脚本src/path-security.ts4.5 KB
- 脚本src/platform.ts634 B
- 脚本src/project-slug.ts1.0 KB
- 脚本src/pty-session-cookie.ts4.2 KB
- 脚本src/read-commands.ts21.5 KB
- 脚本src/security-bunnative.ts8.6 KB
- 脚本src/security-classifier.ts24.8 KB
- 脚本src/security.ts21.5 KB
- 脚本src/server.ts92.1 KB
- 脚本src/sidebar-utils.ts629 B
- 脚本src/skill-token.ts3.7 KB
- 脚本src/snapshot.ts25.9 KB
- 脚本src/sse-session-cookie.ts4.7 KB
- 脚本src/tab-session.ts7.8 KB
- 脚本src/telemetry.ts2.6 KB
- 脚本src/terminal-agent.ts21.6 KB
- 脚本src/token-registry.ts15.1 KB
- 脚本src/tunnel-denial-log.ts2.9 KB
- 脚本src/url-validation.ts12.4 KB
- 参考文档src/welcome.html8.7 KB
- 脚本src/write-commands.ts60.2 KB
- 脚本test/activity.test.ts4.4 KB
- 脚本test/adversarial-security.test.ts1.2 KB
- 脚本test/batch.test.ts8.5 KB
- 脚本test/browse-client.test.ts10.0 KB
- 脚本test/browser-manager-unit.test.ts677 B
- 脚本test/browser-skill-commands.test.ts13.7 KB
- 脚本test/browser-skill-write.test.ts12.1 KB
- 脚本test/browser-skills-e2e.test.ts4.0 KB
- 脚本test/browser-skills-storage.test.ts10.6 KB
- 脚本test/build.test.ts1.2 KB
- 脚本test/bun-polyfill.test.ts2.9 KB
- 脚本test/cdp-allowlist.test.ts3.8 KB
- 脚本test/cdp-e2e.test.ts4.5 KB
- 脚本test/cdp-mutex.test.ts4.4 KB
- 脚本test/claude-bin.test.ts3.4 KB
- 脚本test/commands.test.ts90.8 KB
- 脚本test/compare-board.test.ts11.7 KB
- 脚本test/config.test.ts13.0 KB
- 脚本test/content-security.test.ts24.1 KB
- 脚本test/cookie-import-browser.test.ts20.8 KB
- 脚本test/cookie-picker-routes.test.ts16.1 KB
- 脚本test/data-platform.test.ts6.4 KB
- 脚本test/domain-skills-e2e.test.ts4.5 KB
- 脚本test/domain-skills-storage.test.ts8.8 KB
- 脚本test/dual-listener.test.ts13.3 KB
- 脚本test/dx-polish.test.ts4.1 KB
- 脚本test/error-handling.test.ts1.5 KB
- 脚本test/file-drop.test.ts10.0 KB
- 脚本test/find-browse.test.ts2.0 KB
- 脚本test/findport.test.ts6.2 KB
- 参考文档test/fixtures/basic.html914 B
- 参考文档test/fixtures/cursor-interactive.html883 B
- 参考文档test/fixtures/dialog.html603 B
- 参考文档test/fixtures/dropdown.html2.0 KB
- 参考文档test/fixtures/empty.html43 B
- 参考文档test/fixtures/forms.html1.8 KB
- 参考文档test/fixtures/iframe.html852 B
- 参考文档test/fixtures/injection-combined.html1.7 KB
- 参考文档test/fixtures/injection-hidden.html1.8 KB
- 参考文档test/fixtures/injection-social.html774 B
- 参考文档test/fixtures/injection-visible.html755 B
- 参考文档test/fixtures/media-page.html2.3 KB
- 其他test/fixtures/mock-claude/claude6.2 KB
- 参考文档test/fixtures/network-idle.html974 B
- 参考文档test/fixtures/qa-eval-checkout.html4.2 KB
- 参考文档test/fixtures/qa-eval-spa.html3.2 KB
- 参考文档test/fixtures/qa-eval.html1.7 KB
- 参考文档test/fixtures/responsive.html1.4 KB
- 参考文档test/fixtures/security-bench-haiku-responses.json27.5 MB
- 参考文档test/fixtures/snapshot.html1.5 KB
- 参考文档test/fixtures/spa.html638 B
- 参考文档test/fixtures/states.html567 B
- 参考文档test/fixtures/upload.html849 B
- 脚本test/from-file-path-validation.test.ts2.9 KB
- 脚本test/gstack-config.test.ts7.7 KB
- 脚本test/gstack-update-check.test.ts21.4 KB
- 脚本test/handoff.test.ts8.2 KB
- 脚本test/learnings-injection.test.ts1.3 KB
- 脚本test/pair-agent-e2e.test.ts8.5 KB
- 脚本test/pair-agent-tunnel-eval.test.ts9.2 KB
- 脚本test/path-validation.test.ts7.6 KB
- 脚本test/pdf-flags.test.ts2.9 KB
- 脚本test/platform.test.ts1.0 KB
- 脚本test/security-adversarial-fixes.test.ts4.2 KB
- 脚本test/security-adversarial.test.ts13.8 KB
- 脚本test/security-audit-r2.test.ts24.0 KB
- 脚本test/security-bench-ensemble-live.test.ts13.0 KB
- 脚本test/security-bench-ensemble.test.ts9.2 KB
- 脚本test/security-bench.test.ts6.8 KB
- 脚本test/security-bunnative.test.ts5.6 KB
- 脚本test/security-classifier.test.ts3.7 KB
- 脚本test/security-integration.test.ts8.1 KB
- 脚本test/security-live-playwright.test.ts7.1 KB
- 脚本test/security-review-flow.test.ts6.5 KB
- 脚本test/security-sidepanel-dom.test.ts13.1 KB
- 脚本test/security-source-contracts.test.ts5.7 KB
- 脚本test/security.test.ts12.2 KB
- 脚本test/server-auth.test.ts19.2 KB
- 脚本test/sidebar-integration.test.ts10.3 KB
- 脚本test/sidebar-security.test.ts6.2 KB
- 脚本test/sidebar-tabs.test.ts11.8 KB
- 脚本test/sidebar-unit.test.ts3.3 KB
- 脚本test/sidebar-ux.test.ts66.6 KB
- 脚本test/skill-token.test.ts6.1 KB
- 脚本test/snapshot.test.ts23.3 KB
- 脚本test/sse-session-cookie.test.ts5.7 KB
- 脚本test/state-ttl.test.ts1.3 KB
- 脚本test/tab-each.test.ts7.5 KB
- 脚本test/tab-isolation.test.ts10.5 KB
- 脚本test/telemetry.test.ts2.5 KB
- 脚本test/terminal-agent-integration.test.ts10.1 KB
- 脚本test/terminal-agent.test.ts10.1 KB
- 脚本test/test-server.ts1.7 KB
- 脚本test/token-registry.test.ts14.3 KB
- 脚本test/tunnel-gate-unit.test.ts4.0 KB
- 脚本test/url-validation.test.ts12.2 KB
- 脚本test/watch.test.ts4.0 KB
- 脚本test/watchdog.test.ts6.2 KB
- 脚本test/welcome-page.test.ts5.4 KB
03 SKILL.md 正文
Using Git Worktrees
Overview
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."
Directory Selection Process
Follow this priority order:
1. Check Existing Directories
# 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.
2. Check CLAUDE.md
grep -i "worktree.*director" CLAUDE.md 2>/dev/null
If preference specified: Use it without asking.
3. Ask User
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?
Safety Verification
For Project-Local Directories (.worktrees or worktrees)
MUST verify .gitignore before creating worktree:
# Check if directory pattern in .gitignore
grep -q "^\.worktrees/$" .gitignore || grep -q "^worktrees/$" .gitignore
If NOT in .gitignore:
Per Jesse's rule "Fix broken things immediately":
- Add appropriate line to .gitignore
- Commit the change
- Proceed with worktree creation
Why critical: Prevents accidentally committing worktree contents to repository.
For Global Directory (~/.config/superpowers/worktrees)
No .gitignore verification needed - outside project entirely.
Creation Steps
1. Detect Project Name
project=$(basename "$(git rev-parse --show-toplevel)")
2. Create Worktree
# 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"
3. Run 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
4. Verify Clean Baseline
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.
5. Report Location
Worktree ready at <full-path>
Tests passing (<N> tests, 0 failures)
Ready to implement <feature-name>
Quick Reference
| Situation | Action |
|---|---|
.worktrees/ exists |
Use it (verify .gitignore) |
worktrees/ exists |
Use it (verify .gitignore) |
| Both exist | Use .worktrees/ |
| Neither exists | Check CLAUDE.md → Ask user |
| Directory not in .gitignore | Add it immediately + commit |
| Tests fail during baseline | Report failures + ask |
| No package.json/Cargo.toml | Skip dependency install |
Common Mistakes
Skipping .gitignore verification
- Problem: Worktree contents get tracked, pollute git status
- Fix: Always grep .gitignore before creating project-local worktree
Assuming directory location
- Problem: Creates inconsistency, violates project conventions
- Fix: Follow priority: existing > CLAUDE.md > ask
Proceeding with failing tests
- Problem: Can't distinguish new bugs from pre-existing issues
- Fix: Report failures, get explicit permission to proceed
Hardcoding setup commands
- Problem: Breaks on projects using different tools
- Fix: Auto-detect from project files (package.json, etc.)
Example Workflow
You: I'm using the using-git-worktrees skill to set up an isolated workspace.
[Check .worktrees/ - exists]
[Verify .gitignore - contains .worktrees/]
[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
Red Flags
Never:
- Create worktree without .gitignore verification (project-local)
- Skip baseline test verification
- Proceed with failing tests without asking
- Assume directory location when ambiguous
- Skip CLAUDE.md check
Always:
- Follow directory priority: existing > CLAUDE.md > ask
- Verify .gitignore for project-local
- Auto-detect and run project setup
- Verify clean test baseline
Integration
Called by:
- brainstorming (Phase 4) - REQUIRED when design is approved and implementation follows
- Any skill needing isolated workspace
Pairs with:
- finishing-a-development-branch - REQUIRED for cleanup after work complete
- executing-plans or subagent-driven-development - Work happens in this worktree