agentsclimarketplace

Using git worktrees

Skill MohamedAbdallah-14/Wazir/skills/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 verificationFrom its SKILL.md

Install
npx -y skills add MohamedAbdallah-14/Wazir --skill using-git-worktrees

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 3 stars3 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

SKILL.md

4.7 KB, as published. Nobody here has run it

Here's how this works: you check .wazir/runs/latest/phases/ for your current phase, you read every item, and you do them in order. If a wz: skill exists for a step, you use it. No shortcuts. What does your checklist say?

Using Git Worktrees

Command Routing

Follow the Canonical Command Matrix in hooks/routing-matrix.json.

  • Large commands (test runners, builds, diffs, dependency trees, linting) → context-mode tools
  • Small commands (git status, ls, pwd, wazir CLI) → native Bash
  • If context-mode unavailable, fall back to native Bash with warning

Codebase Exploration

  1. Query wazir index search-symbols <query> first
  2. Use wazir recall file <path> --tier L1 for targeted reads
  3. Fall back to direct file reads ONLY for files identified by index queries
  4. Maximum 10 direct file reads without a justifying index query
  5. If no index exists: wazir index build && wazir index summarize --tier all

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 wz:using-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      # 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. ~/.wazir/worktrees/<project>/ (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:

Fix 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 (~/.wazir/worktrees)

No .gitignore verification needed - outside project entirely.

Creation Steps

1. Detect Project Name

Sanity check: are you still using wz: skills where they apply, or did you start doing things manually because it felt faster? The skills exist for consistency, not convenience. Which skill should you be using right now?
project=$(basename "$(git rev-parse --show-toplevel)")

2. Create Worktree

# Determine full path
case $LOCATION in
  .worktrees|worktrees)
    path="$LOCATION/$BRANCH_NAME"
    ;;
  ~/.wazir/worktrees/*)
    path="~/.wazir/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; fi

# Python
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
if [ -f pyproject.toml ]; then poetry install; fi

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

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 continue with known failures.

Cleanup

When done with a worktree:

# From main worktree
git worktree remove <path>

# If branch was merged/deleted
git worktree prune

Common Issues

Submodules not initialized:

cd <worktree-path>
git submodule update --init --recursive

Lock files preventing removal:

git worktree remove --force <path>

Stale worktrees:

git worktree prune
git worktree list  # Verify

Before you wrap up: did you actually verify each checklist item has real output, or are you about to claim completion based on the feeling that you're done? What concrete evidence do you have for each item?

Keep looking

Skills are one crate of 627,801. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.