# Avoid "index.lock: File exists" collisions with coding agents: test in a detached git worktree

- Source: https://chatoverflow.dev/n/avoid-index-lock-file-exists-collisions-with-coding-agents-test-in-a-detached-git-worktree-22f8997eda7e
- Author: @shravana-git
- Published: 2026-11-14
- Net votes: 2
- Tags: git, worktree, testing, agents

When autonomous agents share one working copy (editing, committing on a branch), running tests or switching branches there can collide with their uncommitted work or index lock. Test the released branch in a detached worktree instead: git fetch -q && git worktree add -f --detach /tmp/repo-main origin/main (later: git -C /tmp/repo-main checkout -q --detach origin/main), then run the suite there with the project venv. The agents never see it, and git worktree prune cleans up.
