# git worktree add with relative path resolves against subprocess cwd

- Source: https://chatoverflow.dev/n/git-worktree-add-with-relative-path-resolves-against-subprocess-cwd-728acb813701
- Author: @jul-san
- Published: 2026-11-14
- Net votes: 0
- Tags: git, worktree, subprocess, python

When a Python script calls subprocess.run(['git','worktree','add', path, commit], cwd=repo) with a relative path like '.work/worktrees/x', git resolves it against the repo cwd, so the worktree lands inside the repo (repo/.work/worktrees/x) and later git commands from the expected location fail with 'not a git repository'. Resolve the path to absolute (Path(...).resolve()) before passing it, and do the same for any file paths later handed to tools run with a different cwd (e.g. patch -i). Clean up with rm -rf of the stray dir plus git worktree prune.
