Git Worktrees

SkillProductivity

Use when a task needs an isolated checkout. Verify the worktree location, keep mutable environments and build outputs local, and run only authorized setup and checks.

Available today. Use it from your connected AI after setup.

Connect ahel once, and every AI you use reads what you have installed.

Then ask your AI: use the Git Worktrees skill

What this skill tells your AI

The instructions your AI receives, as published by btseytlin/ultrapack in skills/git-worktrees/SKILL.md and read by ahel’s review.

Worktrees let you work on multiple branches simultaneously without stashing or switching. Use one when:

  • The task is large enough to warrant isolation
  • You want to run different branches in parallel
  • You're dispatching subagents that shouldn't step on the active workspace

Directory selection — priority order

Safety — confirm project-local dirs are gitignored before creating

For project-local directories (.worktrees/ or worktrees/), verify gitignore:

git check-ignore -q .worktrees 2>/dev/null || git check-ignore -q worktrees 2>/dev/null

If not ignored: add the line to .gitignore, commit (chore: ignore worktree directory), then proceed.

For global directories (outside the project), no gitignore check needed.

Creation

project=$(basename "$(git rev-parse --show-toplevel)")
path="<selected-dir>/<branch-name>"  # e.g. .worktrees/feature-auth
git worktree add "$path" -b "<branch-name>"
cd "$path"

Share environment from main

At creation, a fresh worktree has no project environment — tools that resolve deps via ancestor walks (LSPs, language resolvers) either emit bogus diagnostics or reinstall from scratch. Avoidable: at this moment the worktree's deps are identical to the parent's (same commit base, same manifest). Share the main repo's environment into the worktree. Rebuild locally only if deps later diverge.

Worked example — Python (uv / venv):

main=$(git worktree list --porcelain | awk '/^worktree / {print $2; exit}')
if [ -f pyproject.toml ] && [ ! -e .venv ] && [ -d "$main/.venv" ]; then
  ln -s "$main/.venv" .venv
fi

Absolute symlink target so the link survives nested worktree paths. The ! -e .venv guard means an existing real env or symlink is never overwritten. If main has no .venv, skip — baseline setup below falls through to the install command.

For other stacks, do the analogous share-from-main (node_modules, vendor/bundle, target, …). Go and Gradle share caches globally ($GOMODCACHE, ~/.gradle) — nothing to link.

If the worktree later changes its manifest or lockfile, replace the shared env with a local install (e.g. rm .venv && uv sync). The skill doesn't detect this; it's guidance for whoever edits deps.

Baseline setup — auto-detect and run

[ -f package.json ] && npm install
[ -f Cargo.toml ]   && cargo build
[ -f pyproject.toml ] && [ ! -e .venv ] && (uv sync || pip install -e .)
[ -f go.mod ]       && go mod download

Then run the project's tests to confirm a clean baseline. If tests fail before you've changed anything: stop and report. You can't distinguish future bugs from pre-existing ones.

Report to the user

Worktree ready at <full-path>
Baseline: <test summary, or "skipped — no test command">

Cleanup when task is done

git worktree remove <path>
git branch -D <branch-name>  # only if not merged

Don't leave stale worktrees around. git worktree prune cleans up broken references.

Never

  • Create a project-local worktree without verifying it's gitignored
  • Skip the baseline test run
  • Proceed with failing baseline tests without asking
  • Hardcode setup commands — detect from project files

Signals

GitHub stars
47
Forks
12
Last commit
Sep 2026
Advanced
Catalog kind
skill
Gateway key
git-worktrees
Source
github.com/btseytlin/ultrapack