Worktrees — Multiple Workspaces
How to have several branches open at the same time in separate folders, so you can switch between tasks instantly.
What is a worktree?
A worktree is like having multiple desks in your office, each with a different document open. Normally with Git, you have one desk (one folder). If you want to look at a different branch, you have to close your current work, switch branches, and reopen everything. With worktrees, you just walk over to another desk where that branch is already open and ready.
A git worktree is a separate folder on your computer that is linked to the same repository but has a different branch checked out. You can have as many worktrees as you want, each showing a different branch simultaneously.
Why use worktrees?
No context switching
You are working on a feature but need to check something on the main branch. Instead of saving, switching, checking, switching back, and reopening — you just open the other folder.
Parallel development
Two AI agents (or two developers) can work on different features at the same time, each in their own worktree, without interfering with each other.
Quick comparisons
Want to compare how the app looks on the current branch versus the develop branch? Both are available simultaneously in separate folders.
Safe experiments
Spin up a worktree to try a wild experiment. If it fails, delete the folder. Your main workspace is untouched.
How worktrees relate to branches
develop. Think
of it this way: each desk has a different document, never the same one twice.
One repository, three workspaces. All share the same history but each has a different branch checked out in its own folder.
The folder structure
At BACON-AI, worktrees live inside a .worktrees/ folder within
the project. Here is what the Mesh Hub project looks like on disk:
bacon-ai-local-ai-file-chat/ ← Main workspace (develop branch)
├── client/
├── server/
├── package.json
├── .worktrees/ ← Worktrees folder
│ ├── feature-mesh-hub-v0.2/ ← Worktree 1 (feature/mesh-hub-v0.2)
│ │ ├── client/
│ │ ├── server/
│ │ └── package.json
│ └── feature-physics-controls/ ← Worktree 2 (feature/physics-controls)
│ ├── client/
│ ├── server/
│ └── package.json
└── .git/ ← Shared repository data
.worktrees/ folder is listed in .gitignore,
meaning it is not tracked by Git itself. Worktrees are a local convenience
— they exist on your machine but are not uploaded to GitHub.
The lifecycle of a worktree
Worktrees are temporary workspaces. Once the feature is merged, the worktree folder is removed to keep things tidy.
Worktrees vs. branches — what is the difference?
| Concept | What it is | Analogy |
|---|---|---|
| Branch | A line of development in the project history | A chapter you are rewriting |
| Worktree | A folder on your computer where a branch is checked out | A desk where that chapter is open |
You can have a branch without a worktree (it exists in history but is not currently open anywhere). But you cannot have a worktree without a branch — every desk must have a document on it.
When BACON-AI uses worktrees
BACON-AI runs multiple AI agents simultaneously. Imagine three writers working on the same book at the same time. Each writer sits at their own desk with their own chapter open. They all share the same bookshelf (repository) but nobody is fighting over the same piece of paper. That is worktrees in action.
Common scenarios:
- The orchestrator agent works on
developin the main workspace - A feature agent works on
feature/mesh-hub-v0.2in a worktree - A third agent tests
feature/physics-controlsin another worktree
Key takeaways
- A worktree is a separate folder with a different branch open.
- Worktrees let you work on multiple things at once without switching back and forth.
- Each worktree has its own branch — no duplicates allowed.
- Worktrees are temporary. Delete them when the feature is done.