One Checkout per Job: Worktrees, mise and Worktrunk
Git worktrees, mise and Worktrunk let me review PRs and run parallel agent stories without juggling one checkout. Onboarding got easier too.
Two things kept slowing me down, and for a long time I treated them as separate problems.
Reviewing a pull request properly meant stashing my work, switching branch and restarting everything, then undoing all of it to get back. And with coding agents, one checkout meant one agent and one story at a time.
They turned out to have the same root cause. One checkout was doing two jobs. This is the setup I now use to give each job its own: Git worktrees, mise and, optionally, Worktrunk. Making every checkout set itself up had a side benefit I hadn’t planned for: onboarding onto a repository got much easier too.
I’ve written about part of this before in Running Parallel AI Coding Agents Without Conflicts. That post is the detailed walkthrough for running agents in parallel. This one is the wider picture: why the same setup also fixed reviews, and made onboarding easier along the way.
Worktrees: Git’s best feature with its worst UX
git worktree checks a branch out into its own independent folder. That folder is a worktree: another checkout of the same repository, with its own branch, its own uncommitted changes and its own build output. They all share one .git, so history and objects aren’t duplicated, and a commit made in one is visible from the others straight away.
git worktree add .worktrees/feat-a -b feat-a
That matters because it removes the reasons to juggle a single checkout. No stashing, no second clone, and no agent overwriting another agent’s files. Git also refuses to check out the same branch in two worktrees, which is exactly the guard rail you want.
The idea is brilliant. The commands aren’t. You choose a path for every worktree, you cd around by path, nothing gets set up for you, and cleaning up takes two commands. Worktrunk makes a worktree feel like a branch:
| Job | Plain git | Worktrunk |
|---|---|---|
| Start a story | git worktree add .worktrees/feat-a -b feat-a, then cd |
wt switch -c feat-a |
| Get back to it | Remember where you put it, then cd |
wt switch feat-a |
| Set it up | Copy .env, install packages, pick ports by hand |
Hooks run the setup for you |
| Review a PR | Fetch, find the branch, add a worktree | wt switch pr:123 |
| See what’s open | git worktree list, which shows paths |
wt list, with branch, status and (once configured) URL |
| Clean up | git worktree remove, then git branch -d |
wt remove, which deletes the branch too once merged |
Everything in that table still works with plain git. Worktrunk removes the friction that stops people using worktrees in the first place.
I keep worktrees inside the repository
Most examples, and Worktrunk’s default, put each worktree in a sibling folder next to the main checkout. With a few stories and a review on the go, the parent folder fills up with myproject.feature-auth, myproject.pr-123 and friends.
My preference is a .worktrees folder inside the repository, ignored by Git. Everything for a repository stays in one place, and I always know where to look. In Worktrunk, that’s one line in my user config:
# ~/.config/worktrunk/config.toml
worktree-path = "{{ repo_path }}/.worktrees/{{ branch | sanitize }}"
And one line in the repository’s .gitignore, so the primary checkout doesn’t see the worktrees as untracked files:
.worktrees/
It’s a personal setting rather than a project one, so it lives in user config and not in the committed .config/wt.toml.
Worktrees isolate files, not runtime
This is the part that caught me out. Two worktrees have separate files, but both copies of the app still read the same configuration. Both dev servers want the same port. Both point at the same database, queue and cache.
Unique ports don’t give you data isolation either. Two worktrees on different ports can still migrate and seed the same database. The runtime needs isolating as well, and that’s where mise comes in.
mise is the repository’s front door
mise does three jobs that used to live in three places:
- Tools. It installs and pins the runtimes a repository needs, so nobody has to ask which Node or .NET version to use.
- Environment. It sets environment variables per folder.
- Tasks. It holds the repository’s commands, so
mise tasksanswers “how do I run this?”.
Per-folder environment variables are what make worktrees work at runtime. The committed mise.toml holds the defaults the primary checkout uses. Each linked worktree gets an ignored mise.local.toml that overrides only what must differ:
# .worktrees/feat-a/mise.local.toml, generated and ignored
[env]
FRONTEND_PORT = "14315"
DATABASE_NAME = "demo_feature_a"
RABBITMQ_VHOST = "/feature-a"
REDIS_KEY_PREFIX = "feature-a:"
When you cd into the worktree, those values are just there: for you, for mise run dev, and for any agent working in that folder. The application code doesn’t know anything about worktrees. It reads environment variables.
Keeping worktrees inside the repository has a few side effects here. mise reads config from parent folders, so a nested worktree inherits the primary checkout’s mise.local.toml, including values meant only for the primary, such as its ports. The worktree’s own mise.local.toml overrides them. Trust the primary checkout’s config first, or hooks and agents that can’t prompt will fail with an untrusted-config error. Also exclude .worktrees from any file watchers running in the primary checkout.
Shared services run once, with isolation that’s logical rather than physical: a database per worktree in one Postgres, a vhost per worktree in one RabbitMQ, a key prefix per worktree in one Redis.
Worktrunk hooks tie it together
Worktrunk runs hooks when it creates a worktree. Mine only call mise tasks, in this order:
# .config/wt.toml
[[pre-start]]
trust = "mise trust"
[[pre-start]]
install = "mise install"
[[pre-start]]
worktree_setup = "mise run worktree:setup"
worktree:setup writes that worktree’s mise.local.toml: its ports, database name and other resource names. Because the hooks only call mise, nothing about the isolation depends on Worktrunk. Without it, the same thing is git worktree add .worktrees/<branch>, then mise trust, mise install and mise run worktree:setup.
What it fixed
Reviewing a PR without putting my work down
wt switch pr:123
mise run dev
wt switch -
wt switch pr:123 checks out the pull request into its own worktree, and the same hooks give it its own ports and database. I can run it and click through it, then wt switch - takes me straight back. My branch, my running dev server and any agent working in it never notice. wt remove cleans up afterwards.
Starting the next story while I wait
Agents take a while, and they don’t need me while they work. With one checkout, I watched one agent at a time. Now I start the next story in a new session in my agent harness and tell the agent to set up a worktree for it, something like:
Create a new worktree for the notifications story and work there.
The agent runs wt switch -c for me, the hooks give the worktree its own ports and database, and the agent carries on inside it. It can’t step on the other stories, because none of them share a checkout or a database.
Worktrunk can also do this in one line from the terminal, with wt switch -c feature-notifications -x claude -- "Add a notification bell". That’s handy for scripting, but day to day I stay in the harness.
The parallel agent workflow post has the full setup, including shared Docker services and OAuth redirects, and there’s a demo repository you can clone.
A side benefit: onboarding is a handful of commands
To make worktrees cheap, every checkout had to be able to set itself up. A newcomer’s first clone is just another checkout, so onboarding got the same treatment:
git clone <repo> && cd <repo>
mise trust
mise install
mise run setup
mise run dev
setup runs once in the primary checkout and asks one question at a time. dev starts the normal set of applications together. The same list works for agents, so the instruction file for agents can say “use the mise tasks” instead of repeating how to run everything.
A new problem: forgotten worktrees
One checkout never needed cleaning up. Worktrees do. They’re cheap to create, so they pile up: every finished story and every reviewed PR leaves a folder behind, with its packages, its build output, and its own database, vhost and key prefix in the shared services.
There are a few ways to deal with it, and they all lean on the same Worktrunk command:
wt step prune --dry-run
wt step prune
wt step prune removes worktrees whose branches are merged into the default branch, and their branches with them. It always skips worktrees with uncommitted changes, locked worktrees and the main checkout, and by default it leaves anything younger than a day alone. --dry-run shows what it would remove.
- Ask the agent. In any session: “Clean up any worktrees that are merged and have no uncommitted changes.” The agent previews with
--dry-run, then prunes. - Run it on a schedule. A scheduled job that runs
wt step prunein each repository means merged work disappears without anyone remembering to do it. Approve the repository’s hook commands first, withwt config approvals add, or pass--yes. Otherwise prune skips any worktree whose hooks need approval.
Removing the folder isn’t the whole job. A worktree’s database or vhost survives its folder unless something drops it. Worktrunk runs pre-remove hooks for each worktree it removes, so a hook can call the repository’s cleanup task and take the worktree’s resources with it. Prune removes worktrees in parallel, so make that cleanup task safe to run concurrently.
Honest gaps
- Review becomes the constraint. More stories finish, and every one still needs reviewing and testing. I wrote about that in What happens when code moves faster than feedback?.
- Some things won’t isolate locally. A shared cloud sandbox or a third-party API gets a written rule, not a fix.
- Auth redirects. Microsoft Entra ignores the port on a localhost redirect URI, so one registration covers every worktree. Providers that match the port exactly need a workaround, which I covered in Running Parallel AI Coding Agents Without Conflicts.
- Your machine is the limit. Every worktree runs its own application processes, so there’s a practical ceiling on how many run at once.
- Every repository is different. The demo was wired up by hand. For real repositories, with several APIs, queues and databases, I’ve turned the method into agent skills in my skills repository that work out how to isolate each dependency and keep the setup in sync as the repository changes. That deserves its own post.
One checkout per job
None of these tools is new. Worktrees have been in Git since version 2.5, and mise and Worktrunk each solve one problem well. What changed for me was seeing that reviews and parallel stories were the same problem. One checkout was doing two jobs. Now each job gets its own, and because every checkout can set itself up, the first one, a newcomer’s clone, got easy too.
Comments
Join the conversation on Bluesky.