| name | using-git-worktrees |
| description | Create isolated git worktrees for feature work with safety verification. Use when starting feature branches that need isolation, running parallel agents in separate workspaces, or before executing implementation plans. |
using-git-worktrees
Create isolated worktrees for feature work so each branch gets its own working directory without cloning the entire repository.
When to Use
- Starting a feature branch that needs filesystem isolation from the main worktree
- Running parallel agents that each need their own working directory
- Working on multiple branches simultaneously without stashing
- Before executing an implementation plan that modifies many files
Directory Selection
Check for a worktree directory in this order:
.worktrees/ — project-local, preferred
worktrees/ — alternative project-local
- Ask the user — if neither directory exists
if [[ -d ".worktrees" ]]; then
WORKTREE_DIR=".worktrees"
elif [[ -d "worktrees" ]]; then
WORKTREE_DIR="worktrees"
else
echo "No worktree directory found. Where should worktrees be created?"
echo " 1. .worktrees/ (recommended — hidden, project-local)"
echo " 2. worktrees/"
echo " 3. Custom path"
fi
Safety Verification
Before creating a project-local worktree directory, verify it is gitignored. An unignored worktree directory will pollute git status with thousands of untracked files.
if ! git check-ignore -q "$WORKTREE_DIR" 2>/dev/null; then
echo "WARNING: $WORKTREE_DIR is not in .gitignore"
echo "Add it to .gitignore and commit before proceeding."
echo "$WORKTREE_DIR/" >> .gitignore
git add .gitignore
echo "Staged .gitignore — commit when ready before creating the worktree."
fi
Never skip this check. Creating a worktree in an unignored directory is a common mistake that is tedious to clean up.
Creation Steps
1. Choose a Branch Name
Use Hill90 branch naming conventions from AGENTS.md:
| Type | Prefix | Example |
|---|
| Feature | feat/ | feat/add-auth-flow |
| Bug fix | fix/ | fix/smtp-timeout |
| Refactor | refactor/ | refactor/deploy-script |
| Docs | docs/ | docs/api-reference |
| Enhancement | enhance/ | enhance/logging |
2. Create the Worktree
BRANCH="feat/my-feature"
git worktree add "$WORKTREE_DIR/$BRANCH" -b "$BRANCH"
To create from an existing branch:
git worktree add "$WORKTREE_DIR/$BRANCH" "$BRANCH"
3. Set Up the Worktree
After creation, the worktree needs project dependencies. Detect and run the appropriate setup:
cd "$WORKTREE_DIR/$BRANCH"
[[ -f package-lock.json ]] && npm ci
[[ -f pnpm-lock.yaml ]] && pnpm install --frozen-lockfile
[[ -f yarn.lock ]] && yarn install --frozen-lockfile
[[ -f requirements.txt ]] && pip install -r requirements.txt
[[ -f pyproject.toml ]] && pip install -e .
[[ -f Cargo.toml ]] && cargo build
[[ -f go.mod ]] && go mod download
compgen -G 'tests/scripts/*.bats' >/dev/null 2>&1 && echo "BATS tests available"
4. Verify
git worktree list
cd "$WORKTREE_DIR/$BRANCH"
git branch --show-current
Quick Reference
git worktree list
git worktree remove "$WORKTREE_DIR/$BRANCH"
git worktree prune
git worktree lock "$WORKTREE_DIR/$BRANCH"
Common Mistakes
| Mistake | Consequence | Prevention |
|---|
Worktree dir not in .gitignore | Thousands of untracked files in git status | Always run git check-ignore first |
| Same branch in multiple worktrees | Git refuses — a branch can only be checked out in one worktree | Use git worktree list to check |
| Deleting worktree directory manually | Stale reference in .git/worktrees/ | Always use git worktree remove |
| Forgetting dependency install | Build/test failures in the worktree | Run setup detection after creation |
| Creating worktree from dirty state | Uncommitted changes don't transfer | Commit or stash before creating |
Integration
- using-tmux skill: Use the
using-tmux skill for session-per-worktree orchestration. This skill handles worktree creation; tmux handles running agents in separate terminal sessions within those worktrees.
- Branch naming: Follow AGENTS.md conventions (
feat/, fix/, refactor/, docs/, enhance/).
- Parallel agents: Combine with the
dispatching-parallel-agents skill when multiple agents need isolated workspaces.