askill
using-git-worktrees

using-git-worktreesSafety 95Repository

Use when starting feature work that needs isolation from current workspace, setting up parallel development tracks, or before executing implementation plans. Triggers: 'worktree', 'separate branch', 'isolate this work', 'don't mess up current work', 'work on two things at once', 'parallel workstreams', 'sandboxed workspace'.

3 stars
1.2k downloads
Updated 2/22/2026

Package Files

Loading files...
SKILL.md

Using Git Worktrees

Announce: "Using git-worktrees skill for isolated workspace."

Invariant Principles

  1. Directory precedence: existing > CLAUDE.md > ask user (never assume)
  2. Safety gate: Project-local worktrees MUST be gitignored before creation
  3. Clean baseline: Tests must pass before implementation begins
  4. Auto-detect over hardcode: Infer setup from manifest files

Inputs

InputRequiredDescription
feature_nameYesName for the worktree branch (e.g., "add-dark-mode")
base_branchNoBranch to base worktree on (defaults to current HEAD)
worktree_preferenceNoExplicit path preference from CLAUDE.md or user

Outputs

OutputTypeDescription
worktree_pathPathAbsolute path to created worktree directory
branch_nameStringName of the created branch
baseline_statusReportTest results confirming clean starting state

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. ~/.local/spellbook/worktrees/<project-name>/ (global location)

Which would you prefer?

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/null

If NOT ignored:

  1. Add appropriate line to .gitignore
  2. Commit the change
  3. Proceed with worktree creation

For Global Directory (~/.local/spellbook/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"
    ;;
  ~/.local/spellbook/worktrees/*)
    path="~/.local/spellbook/worktrees/$project/$BRANCH_NAME"
    ;;
esac

# Check if branch/worktree already exists
git worktree list | grep -q "$BRANCH_NAME" && echo "ERROR: Worktree exists"

# 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 || uv sync; fi

# Go
if [ -f go.mod ]; then go mod download; fi

If setup fails: Report specific failure. Ask whether to proceed or troubleshoot.

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>

Autonomous Mode Behavior

Check your context for autonomous mode indicators:

  • "Mode: AUTONOMOUS" or "autonomous mode"
  • worktree preference specified (e.g., "single", "per_parallel_track", "none")

When autonomous mode is active:

Skip These Interactions

  • "Where should I create worktrees?" - use default (.worktrees/) or CLAUDE.md preference
  • "Tests fail during baseline - ask whether to proceed" - proceed if minor, pause if critical

Make These Decisions Autonomously

  • Directory location: Use .worktrees/ as default if no existing directory or CLAUDE.md preference
  • Gitignore fix: Always fix automatically (add to .gitignore + commit)
  • Minor test failures: Log and proceed, major failures pause

Circuit Breakers (Still Pause For)

  • All tests failing (baseline is completely broken)
  • Git worktree command fails (structural git issue)
  • .gitignore cannot be modified (permissions or other issue)
SituationDecision
Directory locationUse .worktrees/ or CLAUDE.md preference
Gitignore fix neededFix + commit automatically
Minor test failuresLog and proceed

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
Worktree already existsReport error, ask for new name
Setup command failsReport failure, ask how to proceed
No package.json/Cargo.tomlSkip dependency install

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

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 git-worktrees skill to set up an isolated workspace.

[Check .worktrees/ - exists]
[Verify ignored - git check-ignore confirms .worktrees/ is ignored]
[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 verifying it's ignored (project-local)
  • Skip baseline test verification
  • Proceed with failing tests without asking
  • Assume directory location when ambiguous
  • Skip CLAUDE.md check
  • Modify files in main workspace while in worktree context
  • Leave orphaned worktrees after feature completion

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

Self-Check

Before reporting worktree ready:

  • Directory location follows precedence (existing > CLAUDE.md > asked)
  • Project-local path verified gitignored (or global path used)
  • git worktree add completed successfully
  • Dependencies installed for project type
  • Baseline tests pass in new worktree

If ANY unchecked: STOP and resolve before proceeding.

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 - Work happens in this worktree (supports both batch and subagent modes)

<FINAL_EMPHASIS> Worktree isolation protects the main workspace from experimental damage. Skipping safety verification causes repository pollution that requires manual cleanup. Proceeding without baseline tests makes it impossible to distinguish new bugs from pre-existing failures. Take the time to do it right. </FINAL_EMPHASIS>

Install

Download ZIP
Requires askill CLI v1.0+

AI Quality Score

94/100Analyzed 2/23/2026

Highly comprehensive and well-structured skill for Git worktree isolation. Excellent when-to-use triggers, clear role definition, detailed safety verification with gitignore checks, and thorough step-by-step instructions. Includes autonomous mode behavior, quick reference tables, and integration notes. Located in dedicated skills folder, making it easily discoverable and reusable across projects.

95
95
90
95
95

Metadata

Licenseunknown
Version-
Updated2/22/2026
Publisheraxiomantic

Tags

ci-cdgithub-actionsllmsecuritytesting