Comprehensive reference for git worktrees. Covers concepts, commands, conflict resolution, and best practices. Invoke with "/worktrees:concepts" or when user mentions "worktree reference", "explain worktrees", "worktree documentation", "worktree commands", "worktree concepts", or "learn about worktrees".
From worktreesnpx claudepluginhub aaronbassett/agent-foundry --plugin worktreesThis skill uses the workspace's default tool permissions.
references/best-practices.mdreferences/commands-reference.mdreferences/conflict-resolution.mdSearches, retrieves, and installs Agent Skills from prompts.chat registry using MCP tools like search_skills and get_skill. Activates for finding skills, browsing catalogs, or extending Claude.
Searches prompts.chat for AI prompt templates by keyword or category, retrieves by ID with variable handling, and improves prompts via AI. Use for discovering or enhancing prompts.
Dispatches parallel agents to independently tackle 2+ tasks like separate test failures or subsystems without shared state or dependencies.
Comprehensive reference for git worktrees in AI development workflows.
Git worktrees allow checking out multiple branches simultaneously in separate directories, all sharing the same .git repository.
Key characteristics:
Ideal for:
Not ideal for:
my-project/
├── .git/ # Shared git directory
├── .gitignore # Must include .worktrees/
├── .worktrees/ # All worktrees live here
│ ├── feature-auth/ # Feature worktree
│ ├── feature-api/ # Another feature worktree
│ └── hotfix-urgent/ # Hotfix worktree
└── src/ # Main working directory
Before creating any worktree, ensure .worktrees/ is gitignored:
grep -q "^\.worktrees" .gitignore 2>/dev/null || echo ".worktrees/" >> .gitignore
git add .gitignore
git commit -m "chore: add .worktrees to gitignore"
Why gitignore? Each worktree contains a complete checkout. Without gitignoring, you'd accidentally commit nested copies of your entire codebase.
| Type | Pattern | Example |
|---|---|---|
| Feature | feature-<name> | feature-auth |
| Agent | <agent-id>-<feature> | agent-42-api |
| Instance | inst-<id> | inst-alpha |
| Hotfix | hotfix-<issue> | hotfix-login |
For multiple concurrent worktrees:
[worktree-name] - projectAvoid port conflicts when running multiple instances:
# Worktree 1
PORT=3001 npm run dev
# Worktree 2
PORT=3002 npm run dev
| Approach | When to Use |
|---|---|
| SQLite per worktree | Simple apps, testing |
| PostgreSQL schemas | Shared DB, isolated data |
| Docker containers | Full isolation |
| In-memory DB | Unit tests |
# SQLite: Different files
DATABASE_URL="file:.worktrees/auth/dev.sqlite"
# PostgreSQL: Different schemas
DATABASE_URL="postgres://localhost/app?schema=worktree_auth"
# Docker: Different containers
docker-compose -p worktree-auth up -d
Keep worktree-specific .env files:
# In worktree
cp ../.env.example .env
# Customize PORT, DATABASE_URL, etc.
Each worktree duplicates working files (not git objects):
# Check worktree sizes
du -sh .worktrees/*
Multiple running dev servers increase memory usage:
top or htop--watch only on active worktreeMany tools use file watchers (webpack, nodemon, etc.):
fs.inotify.max_user_watchesError: fatal: 'branch-name' is already checked out at '/path'
Cause: Each branch can only exist in one worktree.
Solutions:
git worktree listError: fatal: cannot remove worktree with uncommitted changes
Solutions:
git add . && git commit -m "WIP"git stashgit worktree remove --forceProblem: Manually deleted worktree directory leaves stale entry.
Solution: git worktree prune
Problem: Worktree ends up in detached HEAD state.
Solution:
cd .worktrees/<name>
git checkout <branch>
# or create new branch
git checkout -b <new-branch>
| Feature | Git Version |
|---|---|
| Basic worktree | 2.5+ |
worktree list | 2.7+ |
worktree lock/unlock | 2.10+ |
worktree move | 2.17+ |
worktree remove | 2.17+ |
worktree repair | 2.30+ |
--orphan | 2.37+ |
Check version: git --version
| Task | Command |
|---|---|
| Create (new branch) | git worktree add -b <branch> .worktrees/<name> [base] |
| Create (existing branch) | git worktree add .worktrees/<name> <branch> |
| List | git worktree list |
| Remove | git worktree remove .worktrees/<name> |
| Force remove | git worktree remove --force .worktrees/<name> |
| Prune stale | git worktree prune |
| Lock | git worktree lock .worktrees/<name> |
| Unlock | git worktree unlock .worktrees/<name> |
| Move | git worktree move .worktrees/<old> .worktrees/<new> |
| Repair | git worktree repair |
For detailed information, see:
references/commands-reference.md - Complete git worktree command referencereferences/conflict-resolution.md - Handling merge conflictsreferences/best-practices.md - Recommended patterns and tips/worktrees:new - Create a new worktree/worktrees:status - Check worktree health and status/worktrees:finish - Complete and clean up worktree/worktrees:peer - Independent PR-based workflow/worktrees:orchestrator - Multi-subagent parallel development