๐ Full Skill Source โ This is the complete, unedited SKILL.md file. Nothing is hidden or summarized.
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 cm-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 # AlternativeIf found: Use that directory. If both exist, .worktrees wins.
2. Check CLAUDE.md โ
grep -i "worktree.*director" CLAUDE.md 2>/dev/nullIf preference specified: Use it without asking.
3. Ask User โ
If no directory exists and no CLAUDE.md preference: Ask where to create worktrees.
Safety Verification โ
For Project-Local Directories (.worktrees or worktrees) โ
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/nullIf NOT ignored:
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; fi4. Verify Clean Baseline โ
Run tests to ensure worktree starts clean (via cm-quality-gate conventions).
Quick Reference โ
| 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 |
Common Mistakes โ
Skipping ignore verification โ
- Problem: Worktree contents get tracked, pollute git status
- Fix: Always use
git check-ignorebefore 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
Red Flags โ
Never:
- Create worktree without verifying it's ignored (project-local)
- Skip baseline test verification
- Proceed with failing tests without asking
- Assume directory location when ambiguous
Always:
- Follow directory priority: existing > CLAUDE.md > ask
- Verify directory is ignored for project-local
- Auto-detect and run project setup
- Verify clean test baseline
Integration โ
Called by:
- cm-planning - REQUIRED when design is approved and implementation follows
- cm-execution - REQUIRED before executing any tasks
Pairs with:
- cm-code-review - For cleanup after work complete