Agent skill
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
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/devops/using-git-worktrees
SKILL.md
Originally from superpowers plugin. Copied to personal skills for stability.
Using Git Worktrees
Git worktrees create isolated workspaces sharing the same repository, allowing work on multiple branches simultaneously.
Core principle: Systematic directory selection + safety verification = reliable isolation.
Directory Selection Priority
- Check existing directories:
.worktrees/(preferred) orworktrees/ - Check Claude.md for documented preference
- Ask user if neither exists
Safety Verification
For project-local directories: MUST verify .gitignore contains the directory before creating worktree.
If NOT in .gitignore: Add it immediately and commit, then proceed.
Why: Prevents accidentally committing worktree contents.
Creation Steps
- Detect project name:
basename "$(git rev-parse --show-toplevel)" - Create worktree:
git worktree add "$path" -b "$BRANCH_NAME" - Run project setup (auto-detect from package.json, Cargo.toml, etc.)
- Verify clean baseline (run tests)
- Report location and status
Quick Reference
.worktrees/exists — use it (verify .gitignore)worktrees/exists — use it (verify .gitignore)- Both exist — use
.worktrees/ - Neither exists — check Claude.md, then ask user
- Not in .gitignore — add immediately + commit
- Tests fail during baseline — report + ask
Red Flags
Never:
- Create worktree without .gitignore verification (project-local)
- Skip baseline test verification
- Proceed with failing tests without asking
Always:
- Follow directory priority
- Auto-detect and run project setup
- Verify clean test baseline
References
- commands.md - Shell commands for worktree operations
Integration
Pairs with: finishing-a-development-branch (cleanup after work complete)
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?