Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

Git Worktrees for Coding Agents Break on .env, node_modules and Port 3000. Fix All Three

说明与用途

使用 git worktree 进行编码代理时,缺少 .env、node_modules 和唯一端口,导致测试在错误环境中运行。通过 post‑checkout 钩子复制 .env、使用 pnpm 安装依赖并隔离端口,解决了此问题。

问题

Coding agents using git worktrees fail because each worktree lacks its own .env, node_modules, and a dedicated port, causing tests to run against incorrect environments.

结果

After applying the hook, each agent runs in an isolated environment with its own .env, node_modules, and port, eliminating test failures caused by shared state.

工作流

  • 1. Add a post‑checkout hook that runs after git worktree add.
  • 2. In the hook, copy .env from the main worktree to the new worktree.
  • 3. Install dependencies per worktree using pnpm or npm ci, avoiding shared node_modules.
  • 4. Ensure each agent uses a unique port by configuring Vite or Playwright accordingly.

证据

Git worktree add creates a folder and checks out a commit into it. The new worktree shares the repository's history and config with your main checkout. It gets the tracked files of that commit and nothing else.

来源

Symlinking .env into each worktree looks tidy and causes trouble later. Every worktree then reads and writes one file.

来源

pnpm keeps each package once in a content-addressable store and hard-links files from there, "consuming no additional disk space".

来源

  • 记录日期: 2026-10-14T00:40:59.458Z