Setup Script Should Support Git Worktrees Ally Piechowski argues that setup scripts should support Git worktrees to isolate ports, databases, and state for safe parallel development, sharing one Docker stack while deriving a readable worktree identity and allocating unique resources via a locked registry. The approach enables multiple coding agents to run unrelated changes simultaneously without runtime collisions. Your Setup Script Should Support Git Worktrees A worktree-aware setup script can diagnose missing tools, share one Docker stack, and isolate ports, databases, and state for safe parallel development. Ally Piechowski · · 5 min readOn one production app I work on, a fresh Git worktree becomes runnable with one setup script: bin/setup Setup prepares the environment and exits, then the normal development command runs. I’ll use bin/dev here as shorthand for whatever command the repository already uses. Setup doesn’t hide the server inside a clever process manager. bin/setup is a repo-owned executable that turns a checkout into a working development environment. Call it make setup or script/bootstrap if that fits your project. The interface matters more than the name: one command returns either a ready repository or exact repair instructions. The same command should work from every Git worktree. Parallel coding agents made this important enough to treat as ordinary development infrastructure. A Second Checkout Is Not a Second Environment A Git worktree https://git-scm.com/docs/git-worktree.html is another checkout with its own working tree, HEAD , and index while sharing the repository’s common Git data. That separation is great for code. Git does not know that both copies of the app want the same port, database, cache keys, callback URL, Terraform state, or container name. This works until two worktrees need to run: git worktree add ../app-payment-fix -b payment-fix cd ../app-payment-fix bin/setup bin/dev A setup script written for one permanent clone can copy the same .env and point every checkout at the same databases. When two worktrees start, their dev servers can fight for host ports. Compose projects can also overlap when they reuse a project name or fixed container, network, or volume names, and published ports still collide. The second worktree either fails to start or quietly shares state. Worktrees existed long before coding agents. What changed is frequency. Keeping two branches open used to be an occasional convenience. Now several agents can implement and test unrelated changes at once. Their files are isolated by Git; their runtime state has to be isolated by the repository. Share Services, Isolate Names Running a complete Docker stack for every worktree is the simplest mental model and often the wrong default. Databases, object storage emulators, mail catchers, and other local services can be expensive compared with an app process. I run one shared stack, then give each worktree its own ports, databases, and resource names. | Shared once per machine | Isolated per worktree | |---|---| | Database and cache servers | Development and test database names, cache namespace | | Local service containers | Queue names, buckets, callback URLs, infra resource names | | Package-download and tool caches | App port, environment file, logs, PIDs, local state | The setup script derives a readable worktree identity, checks it against a small local registry, then writes generated configuration such as: WORKTREE ID=