DEV Community

Ganesh Joshi
Ganesh Joshi

Posted on

Git Worktrees for Parallel AI Agent and Human Branches

This post was created with AI assistance and reviewed for accuracy before publishing.

Trending in 2026: “agent runs” are normal. You might kick off a long AI coding agent job on a feature branch while you fix a production bug elsewhere. Git worktrees let you keep two checkouts of the same repository without a second clone, sharing objects on disk.

Why agents make worktrees matter

Agent runs often leave dirty trees, build artifacts, or lockfiles mid-flight. Stashing works but is easy to forget. A second worktree at ../my-repo-hotfix checked out to main keeps your mental model clean.

Commands that matter

git worktree add ../path branch-name creates a new directory. git worktree list shows entries. git worktree remove cleans up. You cannot check out the same branch in two worktrees; Git blocks that to protect refs.

node_modules per tree

Each worktree has its own working files. Run npm install or pnpm install in each. Document that in team onboarding so CI and laptops behave predictably.

Practical takeaway

Use worktrees when you juggle human work and agent work on different branches. For authoritative behavior, rely on git-worktree manual pages.

Top comments (0)