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
Add this skill
npx mdskills install sickn33/using-git-worktreesExcellent isolated workspace setup with smart detection, safety checks, and robust edge case handling
1---2name: using-git-worktrees3description: 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 verification4---56# Using Git Worktrees78## Overview910Git worktrees create isolated workspaces sharing the same repository, allowing work on multiple branches simultaneously without switching.1112**Core principle:** Systematic directory selection + safety verification = reliable isolation.1314**Announce at start:** "I'm using the using-git-worktrees skill to set up an isolated workspace."1516## Directory Selection Process1718Follow this priority order:1920### 1. Check Existing Directories2122```bash23# Check in priority order24ls -d .worktrees 2>/dev/null # Preferred (hidden)25ls -d worktrees 2>/dev/null # Alternative26```2728**If found:** Use that directory. If both exist, `.worktrees` wins.2930### 2. Check CLAUDE.md3132```bash33grep -i "worktree.*director" CLAUDE.md 2>/dev/null34```3536**If preference specified:** Use it without asking.3738### 3. Ask User3940If no directory exists and no CLAUDE.md preference:4142```43No worktree directory found. Where should I create worktrees?44451. .worktrees/ (project-local, hidden)462. ~/.config/superpowers/worktrees/<project-name>/ (global location)4748Which would you prefer?49```5051## Safety Verification5253### For Project-Local Directories (.worktrees or worktrees)5455**MUST verify directory is ignored before creating worktree:**5657```bash58# Check if directory is ignored (respects local, global, and system gitignore)59git check-ignore -q .worktrees 2>/dev/null || git check-ignore -q worktrees 2>/dev/null60```6162**If NOT ignored:**6364Per Jesse's rule "Fix broken things immediately":651. Add appropriate line to .gitignore662. Commit the change673. Proceed with worktree creation6869**Why critical:** Prevents accidentally committing worktree contents to repository.7071### For Global Directory (~/.config/superpowers/worktrees)7273No .gitignore verification needed - outside project entirely.7475## Creation Steps7677### 1. Detect Project Name7879```bash80project=$(basename "$(git rev-parse --show-toplevel)")81```8283### 2. Create Worktree8485```bash86# Determine full path87case $LOCATION in88 .worktrees|worktrees)89 path="$LOCATION/$BRANCH_NAME"90 ;;91 ~/.config/superpowers/worktrees/*)92 path="~/.config/superpowers/worktrees/$project/$BRANCH_NAME"93 ;;94esac9596# Create worktree with new branch97git worktree add "$path" -b "$BRANCH_NAME"98cd "$path"99```100101### 3. Run Project Setup102103Auto-detect and run appropriate setup:104105```bash106# Node.js107if [ -f package.json ]; then npm install; fi108109# Rust110if [ -f Cargo.toml ]; then cargo build; fi111112# Python113if [ -f requirements.txt ]; then pip install -r requirements.txt; fi114if [ -f pyproject.toml ]; then poetry install; fi115116# Go117if [ -f go.mod ]; then go mod download; fi118```119120### 4. Verify Clean Baseline121122Run tests to ensure worktree starts clean:123124```bash125# Examples - use project-appropriate command126npm test127cargo test128pytest129go test ./...130```131132**If tests fail:** Report failures, ask whether to proceed or investigate.133134**If tests pass:** Report ready.135136### 5. Report Location137138```139Worktree ready at <full-path>140Tests passing (<N> tests, 0 failures)141Ready to implement <feature-name>142```143144## Quick Reference145146| Situation | Action |147|-----------|--------|148| `.worktrees/` exists | Use it (verify ignored) |149| `worktrees/` exists | Use it (verify ignored) |150| Both exist | Use `.worktrees/` |151| Neither exists | Check CLAUDE.md → Ask user |152| Directory not ignored | Add to .gitignore + commit |153| Tests fail during baseline | Report failures + ask |154| No package.json/Cargo.toml | Skip dependency install |155156## Common Mistakes157158### Skipping ignore verification159160- **Problem:** Worktree contents get tracked, pollute git status161- **Fix:** Always use `git check-ignore` before creating project-local worktree162163### Assuming directory location164165- **Problem:** Creates inconsistency, violates project conventions166- **Fix:** Follow priority: existing > CLAUDE.md > ask167168### Proceeding with failing tests169170- **Problem:** Can't distinguish new bugs from pre-existing issues171- **Fix:** Report failures, get explicit permission to proceed172173### Hardcoding setup commands174175- **Problem:** Breaks on projects using different tools176- **Fix:** Auto-detect from project files (package.json, etc.)177178## Example Workflow179180```181You: I'm using the using-git-worktrees skill to set up an isolated workspace.182183[Check .worktrees/ - exists]184[Verify ignored - git check-ignore confirms .worktrees/ is ignored]185[Create worktree: git worktree add .worktrees/auth -b feature/auth]186[Run npm install]187[Run npm test - 47 passing]188189Worktree ready at /Users/jesse/myproject/.worktrees/auth190Tests passing (47 tests, 0 failures)191Ready to implement auth feature192```193194## Red Flags195196**Never:**197- Create worktree without verifying it's ignored (project-local)198- Skip baseline test verification199- Proceed with failing tests without asking200- Assume directory location when ambiguous201- Skip CLAUDE.md check202203**Always:**204- Follow directory priority: existing > CLAUDE.md > ask205- Verify directory is ignored for project-local206- Auto-detect and run project setup207- Verify clean test baseline208209## Integration210211**Called by:**212- **brainstorming** (Phase 4) - REQUIRED when design is approved and implementation follows213- Any skill needing isolated workspace214215**Pairs with:**216- **finishing-a-development-branch** - REQUIRED for cleanup after work complete217- **executing-plans** or **subagent-driven-development** - Work happens in this worktree218
Full transparency — inspect the skill content before installing.