

Join the discussion
Write your take first — we'll ask for email only when you're ready to publish.
- Hacker News
- Working on an embedded device that requires building firmware images, etc, I've taken to using docker containers with a COW overlay. I have a vibe-coded tool which checks out the latest and does a clean compile, creating a base directory. Then I spawn a build container on top of that. Every build is warm, as they share ccache and page cache. Huge speed up for parallel builds and I never OOM. Every build also sees the same directory structure, simplifying instructions, etc for the agents.
- There's a huge limitation with work trees that makes them borderline unusable: they can never be active on the same branch. Which includes that you can only ever have one on the master branch.by on_the_train
- Yeah they aren't worth the trouble just because of this. Multiple checkouts are the way to go unless your repo is so huge that you can't afford the disk space. You can clone them from each other so you don't need to download the repo over and over and you can send branches back and forth locally if you really need to, though I never do.by modeless
- Dang I read this as
> Parallel development without the headaches from using Git worktree
Read the whole thing just waiting for the complaints to start!
by hankbond - Sameby w4lker
- The one real caveat to this is that if your application has particularly heavy cold starts it can be hard to actually run your worktrees. I usually end up swapping to a regular checkout as each worktree is due for hands-on attention.by Vanit
- Same!
- I'm curious what the constraint preventing you from optimizing the cold start time - can you share more?by lacunary
- I use a top level meta-repository to create a virtual monorepo of all my repositories and vendor their upstreams, then use worktrees off off the submodules to prepare patches. I never need to change directory from the root meta-repository even with multiple agents. Gives you a full monorepo experience without actually having to own any of the parts, every agent has its own isolated worktree so does not conflict.by tlarkworthy
- Doesn't that mean that if you need to work on several repos for a feature at the same time, you'd have to WT each submodule compared to a single WT for a monorepo? Do you use a custom orchestration layer to fire all commands or lets agents manage the WTs?by Klaster_1
- Having gone down the worktree rabbit hole for a month or so, I am giving up in favor of multiple checkouts to enable many agents to work across many repos.
Worktrees worked great for me when my agents' work was mostly contained to a single repo (they got me to finally hitting rate limits, not that that was a goal). As my homelab scales, agents increasingly work across multiple repos, and that's where (my approach to) worktrees broke down; agents were spawned in a repo worktree and so avoided stepping on the toes of other agents in the same repo without any special instruction, but as soon as they needed to touch another repo, they would default to working in that repo directly, without a worktree, and thus collide with other agents, and muddy a merge process that expected the main repo clone to be clean (which turns out to have been an unnecessary design quirk, but resolving it would still not stop agents from stepping on each other's toes in secondary repos).
After a detour through ZFS dataset clones and some mounting magic that made /srv/src/ appear to be a distinct hierarchy for each agent process, I am simplifying even further and giving each agent a bare directory (sth like /srv/dev/<slug>/) where they can check out any repos they want. The git remote (/srv/git/) becomes the only integration point.
Maybe I should just bite the bullet and move into containers, but performant as they are the ergonomics still bum me out.
Edit: I may actually hold on to ZFS datasets with mounting magic. It does add a bit of complexity to dev tools, but it also reduces path-based trust bloat in harness configs, provides some interesting zfs features (zfs diff, etc)... And it's done.
by pkghost - Maybe it's simple, but I just put the agents in a chat room and have them talk to each other.by 2pigeons
- Fossil SCM, conventionally, has been thus way by default.by thunderbong
- One struggle I've had when working with worktrees is not a problem with the worktrees themselves but instead how my Intellij manages project configurations. I can't for the life of me get it set up so my configuration can sit relative to multiple worktrees. There's probably a plugin which solves the issue, but at least in my experience the .idea config folder is rooted in its current directory and very difficult to migrate to another folder or worktree. I end up having to re-establish project linting rules, run configurations, what have you, for each new worktree and it becomes too much of a hassle for anything short-lived.by esposito
- I had a related issue in VSCode - my project definition is stored in the main checkout and is git ignored. When I WT the repo and open an instance of VSCode for it, no project is attached to it, breaking the dev env (scripts, settings, etc.). What worked for me was a VSCode WT extension that allows you to run arbitrary hooks before and after WT checkout. In checkout one, I symlink the VSCode project. This solves the issue and as a bonus, and project changes propagate between all open instances. The only drawback is that VSCode chats/extensions are path scoped, so you lose conversation history and per project extension on/off state that's stored in the VSCode global DB.by Klaster_1
- IntelliJ added worktree “support” but it’s really just a way to create a new project.
I suspect it’ll take a while before we see a shared configuration across worktrees because the .idea folder contains mutable state.
by sa46 - I use git worktrees daily. I'm surprised by how hard it can be to explain them to people who have never used them. Lately I've settled on "like clones, but sharing a .git directory." The article tries to get this across by comparing them to branches, but I think clones are a more intuitive concept to compare against.
To solve some of the ergonomics issues (command verbosity, manual commands to copy over .env files and install dependencies), I wrote autowt, which is a lightweight but powerful worktree manager: https://steveasleep.com/autowt/
Once I dialed in the cli experience, I basically stopped typing 'git checkout <branch>' to change tasks, because it's easier to ignore working directory state when flipping between tasks.
by irskep - I just ran into a situation where I had two Claude instances working in the same repo on two different, independent issues. I noticed the sessions were thrashing a bit on which branch they were on because each was taking control from the other session. That’s when it hit me why I need worktrees.by rhyperior
- Maybe I'm stubborn, but even in the age of AI, I still use multiple git clones/directories of the same project, e.g.:
very rarely use more than 4–5 per project. Maybe I'm just avoiding wrapping my head around worktrees and actually trying them out.~/dev/projectx ~/dev/projectx2 ~/dev/projectx3 ~/dev/projectx4Benefits: These clones act as semi-permanent directories:
- Helps with caching for heavy Docker usage (think of repeated parallel unit, e2e tests)
- I've color-coded my terminal tabs for each clone so I can instantly tell where I am at a glance (kinda like tab groups just with colors)
Maybe if for some reason I need double digits clones of a project I will be more forced to use git worktrees because then it will be annoying to remember in which directory a branch clone lives.
by therealmarv - I'm also stubborn. I clone multiple copies of the repo. I'm currently at two at my job right now, because I was trying to vibe-code an E2E test suite.
I'm probably missing something that people see as a huge advantage of having multiple streams of work large enough to require a long-running branch. I just finish working on the current branch and then switching to another branch. If work can't be accomplished and merged into `main` within a small amount of time, I'm almost certainly doing something wrong.
- this is basically what worktrees do, though? except git 'knows' about all the associated branches, so you don't have to deal with pushing/pulling in order to merge xyz branch, etc.by agrm
- My mind inserted an 'of' in the title. I thought the article was about doing parallel development without using Git worktrees. Prior to AI, I never used worktrees. Now I use them all the time. I think it's both due to that AI agents are well suited to do parallel development, but also due to that Claude helps me avoiding the headaches of using Git worktreesby mkirsten
- The real problem for parallel dev is ensuring parallel dev environments can seamlessly co-exist without treading on each other. As soon as one of them wants to open a port, talk to an external database or write to a shared location as part of testing you have them conflicting with each other.
Much of this is a legacy dev issue where there was never so much of an assumption that parallel ephemeral dev environments would be in play in the first place. But legacy dev is still most of dev.
by zmmmmm - I just have a handful of ‘hot desks’ I assign different agents to - each desk is numbered, and the numbers inform the ports. So my first agent (001, because it’s an agent after all) uses 8081 for the web server, 3001 for the database, 8001 for the api service, etc - and 002 would use —2 for all the same.
Nice and neat, nobody’s toes get stepped on.
by mock-possum - To avoid that, the code should have ways to override default ports or paths for testing. Then, when testing, ask the OS for a free port or temporary file, and tell the tested code to use that instead of its default. This also allows running tests concurrently.
In what case would talking to an external DB be a problem? Databases support parallel queries.
by lefra - Easy: each worktree starts services on new ports. https://termic.dev goves you ENV variables for this, oir you definee your own custom named variables, and termic assigns ports for each wotktree.
Or if the stack is too complex to start it in parallel, use spotlight to sync changes to main checkout from a single worktree at a time. You can only test one at a time, let's be serios. https://termic.dev/docs/spotlight/
by SimionBaws