Skip to content

๐Ÿ“‹ Full Skill Source โ€” This is the complete, unedited SKILL.md file. Nothing is hidden or summarized.

โ† Back to Skills Library

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 โ€‹

bash
# 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 โ€‹

bash
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: Ask where to create worktrees.

Safety Verification โ€‹

For Project-Local Directories (.worktrees or worktrees) โ€‹

MUST verify directory is ignored before creating worktree:

bash
# 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":

  1. Add appropriate line to .gitignore
  2. Commit the change
  3. 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 โ€‹

bash
project=$(basename "$(git rev-parse --show-toplevel)")

2. Create Worktree โ€‹

bash
# 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:

bash
# Node.js
if [ -f package.json ]; then npm install; fi
# Rust
if [ -f Cargo.toml ]; then cargo build; fi

4. Verify Clean Baseline โ€‹

Run tests to ensure worktree starts clean (via cm-quality-gate conventions).

Quick Reference โ€‹

SituationAction
.worktrees/ existsUse it (verify ignored)
worktrees/ existsUse it (verify ignored)
Both existUse .worktrees/
Neither existsCheck CLAUDE.md โ†’ Ask user
Directory not ignoredAdd to .gitignore + commit
Tests fail during baselineReport failures + ask

Common Mistakes โ€‹

Skipping ignore verification โ€‹

  • Problem: Worktree contents get tracked, pollute git status
  • Fix: Always use git check-ignore 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

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

Open Source AI Agent Skills Framework