Dependencies
Each worktree needs its own node_modules, because packages resolve relative to the folder. With pnpm the cost is small: its store links the same files into every worktree instead of copying them.
cd ~/code/payments-api-ledger-export pnpm install --frozen-lockfile
Untracked files
Files git does not track, such as .env or local certificates, are not in a new worktree. Copy them from the main checkout:
cp ../payments-api/.env .env
One port per worktree
Two dev servers cannot share a port. Give each worktree its own:
Vite takes the port on the command line:
pnpm dev --port 5174
Next.js and many Node servers read PORT:
PORT=3001 pnpm dev
Vite moves to the next free port by itself unless strictPort is set, and prints the address it chose. Read it from the output rather than assuming.
Worktrees that share a database or a queue share its data too. Before you run migrations or workers, name a database or schema and a queue of its own in each worktree’s .env.
With Dockazor
The project’s .dockazor/config.json holds the commands, tracked with the project so everyone gets the same setup:
{
"base": "main",
"setup": "pnpm install && cp ../../../.env .env",
"run": { "command": "pnpm dev" },
"publish": { "checks": "pnpm test" }
}setupruns in each new worktree before its first chat. With worktrees in their default folder,../../../is the project. If it fails, fix it and choose Run Setup in the Terminal tab.runis the server command each worktree runs. Give each its own port as above; Dockazor reads the address the server prints, and Preview ⌘5 shows its page, from a container too.- Every key, and when Dockazor asks you to accept a change: the docs.