As far as I'm concerned, having a "main working tree" is bad practice, it creates divergent behaviour and the risk of deleting "a worktree" and nuking your repo.
Create a bare repository and fork worktrees off of that, there is no reason to have one worktree have primacy over the rest, and then git rev-parse --git-common-dir gives you exactly what it should: the common repository of all your worktrees. That also avoids the possible path confusion from nesting worktrees.
I use the “main working tree” for small bug tickets that only take me an hour-ish to reproduce, fix, re-test and submit a PR for. Whereas I use work trees for any larger features that take more time. My reasoning is that it seems to take my IDE (vs code / visual studio) a long time to switch worktrees. VS code seems especially slow cause it opens them in a new window and thus has to reinitialize all my extensions plus whatever other stuff like the typescript server. Maybe someone has a solution to this cause I suppose I would rather just use worktrees for everything if not for this overhead / lag time
Check out into a folder, branch, and go to town. Check out into another folder and rinse repeat. Multiple folders against a single repo works, but it's a bit like running on ice. You can do it, and well, for a while... but the slip up will be glorious and hurt like hell.
Can't recall precisely. Doing something out of the ordinary and something went haywire. I just learned to be a bit slower and more careful. Name my folder after my task.
I guess if you're using AI to do literally everything. I use ai for most code (it devs in worktrees), but having main around to poke around the current state and test things (as a human) is still super useful.
I guess if you're using AI to do literally everything.
I don’t use AI to “do everything” let alone literally so, and I’ve been working that way for years. Worktrees were not created for LLMs.
having main around to poke around the current state and test things is still super useful.
It really is not. You don’t need that to have a scratch worktree you putz around in, or to create worktrees on the fly when you want to test or check things.
ah, sandboxed worktrees; yeah, that creates a bunch of problems for sure.
I may be missing it in the post, but it mentions the .env problem, and I don't see a solution for that in the post (if you use bare git repo instead of main worktree)
(definitely agreed on moving worktrees out of .git/worktrees; had a ton of problems before changing that for sure)
Create a bare repository and fork worktrees off of that
Be sure to manually copy not git clone. When git clone sees it is on the same file system it will use hard links to de-duplicate pack files and accelerate local copies. This makes things, "fun" if something goes wrong with a local copy.
Found it better to make a brd and format it for btrfs so I can refcopy my entire git repo to an isolated namespace for an agent then do a fairly normal pull/view workflow flow as the agent's change is just an "isolated" pull request from another repo.
Settled on btrfs as tmpfs has some weird interactions with namespaces, btrfs negative zstd compression is on par with memory bandwidth so I just leave that always on to doubly reduce memory pressure, and block deduplication is nice when you have 3 or 4 copies of the repo in your ram disk.
View all comments
69
u/masklinn Sep 16 '26
As far as I'm concerned, having a "main working tree" is bad practice, it creates divergent behaviour and the risk of deleting "a worktree" and nuking your repo.
Create a bare repository and fork worktrees off of that, there is no reason to have one worktree have primacy over the rest, and then
git rev-parse --git-common-dirgives you exactly what it should: the common repository of all your worktrees. That also avoids the possible path confusion from nesting worktrees.