Skip to main content

Should Git Worktrees Go Inside the Repo or Next to It?

Next to it. A worktree nested inside the main checkout needs an ignore rule, or Git and your tools treat it as part of the project.

The Fix​

Create worktrees in a sibling directory:

git worktree add -b feature ../repo-feature

If you want them inside the repository, ignore the folder first. .git/info/exclude keeps the rule out of the shared .gitignore:

echo "/worktrees/" >> .git/info/exclude
git worktree add -b feature worktrees/feature

Why It Happens​

A linked worktree is a full checkout with a .git file at its root. Inside the main checkout, Git sees an untracked directory:

$ git worktree add -b nested ./wt-nested
$ git status --short
?? wt-nested/

git add -A then stages it as a gitlink, the same entry a submodule uses. Git 2.43 warns:

warning: adding embedded git repository: wt-nested
hint: You've added another git repository inside your current repository.

If you commit that, the repository records a submodule entry with no .gitmodules file and no URL.

Git ignores the nested folder once an ignore rule covers it, but other tools may not. grep -r, test runners, and file watchers walk the directory tree. In a quick check, grep -rl from the main checkout matched both ./a.txt and ./wt-nested/a.txt. A test runner can find every test twice, and a dev server can rebuild when another worktree changes.

Choosing a Layout​

LayoutExampleNeeds an ignore rule
Sibling../repo-featureNo
Dedicated folder beside the repo../repo.worktrees/featureNo
Nested./worktrees/featureYes, plus tool config

A dedicated folder beside the repository keeps many worktrees together without nesting them. git worktree list shows every path either way.

How Treq Handles It​

Treq nests workspaces under .treq/workspaces/. It writes .treq/.gitignore so Git ignores everything there except config.yaml and workflows/.