Git Worktree Setup, App Isolation, and Cleanup

Set up parallel Git worktrees with separate ports, secrets, dependencies, and local data, then retire them safely.

Development / Engineeringgit-worktreesparallel-development
by AgentVoltv1.0.0
Free to sign up · every skill included with AgentVolt Pro

Before & after

Same prompt, same agent — the only difference is the skill.

Prompt“I need to work on two feature branches at the same time without switching branches constantly.”
Beforegeneric AI agent
You could use Git worktrees to work on multiple branches simultaneously. Worktrees are a Git feature that lets you check out different branches in separate directories. You'd need to manage the directory structure, make sure each worktree has the right environment set up, and handle cleanup when you're done. It's a bit manual, but it's definitely doable. You might also want to think about how to handle things like running servers on different ports for each worktree. Would you like some general guidance on how to set this up?
Afterwith Git Worktree Setup, App Isolation, and Cleanup
WORKTREE SETUP

wg create --branch feature/auth feature-auth
  → Creates .worktrees/feature-auth with isolated git state
  → Returns port assignment: 3001 (main is 3000)

wg create --branch feature/payments feature-payments
  → Creates .worktrees/feature-payments
  → Assigns port 3002

ISOLATION SUMMARY

Main worktree: ./ → PORT 3000 → node_modules/ → .env.local
feature-auth: .worktrees/feature-auth → PORT 3001 → symlinked node_modules (shared) → .env.3001
feature-payments: .worktrees/feature-payments → PORT 3002 → symlinked node_modules → .env.3002

ENVIRONMENT SYNC

Each worktree gets DATABASE_URL, API_KEY from shared .env.production (read-only)
PORT and LOG_FILE override per worktree

CLEANUP

wg cleanup → removes all stale worktrees, frees ports, confirms git branches still exist before deletion

About this skill

Two branches are checked out, but both apps still hit the same database, fight over port 3000, or overwrite shared files. This skill sets up Git worktrees with explicit runtime isolation and checks what is actually running before calling the setup complete.

What it does

  • Creates worktrees from an explicit base commit without disturbing the current checkout.
  • Detects occupied branches, conflicting paths, locked worktrees, and stale registrations.
  • Assigns separate app ports, callback URLs, local data stores, and worker namespaces where the project supports them.
  • Provisions ignored environment files without exposing secrets or sharing writable dependency directories.
  • Verifies process ownership, effective ports, and application identity for each running instance.
  • Retires worktrees after checking tracked changes, untracked and ignored files, running processes, and branch merge status.

What you get

A task-to-worktree map with branches, base commits, runtime settings, launch commands, and verification results. Cleanup includes a record of what was removed and what was preserved.

Best for

Developers running multiple features, experiments, review checkouts, or agent sessions in the same repository, especially when each checkout needs its own running app.

SKILL.md preview

SKILL.md
---
name: git-worktree-setup-app-isolation-and-cleanup
description: >-

… (sign up to view the full skill)
Sign up to view, copy, and install the full skill

More development skills

View all Development skills →