Skip to content

Commit 15fd612

Browse files
committed
docs: add worktrees feature documentation
1 parent 66b56d5 commit 15fd612

2 files changed

Lines changed: 209 additions & 0 deletions

File tree

docs/features/worktrees.mdx

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
---
2+
description: Use Git worktrees to work on multiple branches simultaneously with Roo Code, each in its own VS Code window.
3+
keywords:
4+
- worktrees
5+
- git worktrees
6+
- multiple branches
7+
- parallel development
8+
- branch management
9+
- agentic coding
10+
---
11+
12+
# Worktrees
13+
14+
Git worktrees allow you to work on multiple branches of the same repository simultaneously by keeping them in different directories. Each worktree gets its own VS Code window with Roo Code, enabling parallel development without branch switching.
15+
16+
This is particularly powerful for agentic coding workflows where you might want to:
17+
18+
- Test different implementation approaches in parallel
19+
- Review pull requests without disrupting your current work
20+
- Run multiple tasks on different branches simultaneously
21+
- Maintain separate environments for development and debugging
22+
23+
:::note Requirements
24+
- Git must be installed on your system
25+
- Your workspace must be a Git repository
26+
- Multi-root workspaces are not supported
27+
- Workspace must be at the repository root (not a subfolder)
28+
:::
29+
30+
---
31+
32+
## Getting Started
33+
34+
### Accessing Worktrees
35+
36+
You can access the worktrees feature in two ways:
37+
38+
1. **Home Screen**: When you have multiple worktrees, a worktree selector appears at the top of the chat interface
39+
- Click the selector to see all your worktrees
40+
- Click on any worktree to switch to it
41+
- Click the `+` button to create a new worktree
42+
43+
2. **Settings Panel**: Navigate to Settings <Codicon name="gear" /> → Worktrees
44+
- View and manage all your worktrees
45+
- Create new worktrees
46+
- Delete existing worktrees
47+
- Configure `.worktreeinclude` settings
48+
49+
### Creating Your First Worktree
50+
51+
1. Open the Roo Code settings by clicking the gear icon <Codicon name="gear" />
52+
2. Navigate to the "Worktrees" section
53+
3. Click the "Create worktree" button
54+
4. Fill in the required fields:
55+
- **Base Branch**: The branch to create your new branch from (typically `main` or `develop`)
56+
- **Branch Name**: Name for the new branch (e.g., `worktree/feature-name`)
57+
- **Worktree Path**: Location where the worktree will be created (suggested path is `~/.roo/worktrees/`)
58+
5. Click "Create"
59+
6. Choose whether to open the new worktree in a new window or stay in your current window
60+
61+
The worktree will be created with all the files from the base branch, and you can immediately start working on it.
62+
63+
---
64+
65+
## Key Functionality
66+
67+
### Switching Between Worktrees
68+
69+
Once you have multiple worktrees, switching between them is seamless:
70+
71+
**From the Home Screen**:
72+
- Click the worktree selector at the top of the chat
73+
- Select the worktree you want to switch to
74+
- Choose whether to switch in the current window or open a new window
75+
76+
**From Settings**:
77+
- Navigate to Settings → Worktrees
78+
- Click on any worktree to switch to it in the current window
79+
- Click the <Codicon name="arrow-up-right" /> icon to open in a new window
80+
81+
:::tip Multiple Windows
82+
Opening worktrees in new windows allows you to have multiple tasks running in parallel, each in its own workspace. This is ideal for comparing different approaches or working on multiple features simultaneously.
83+
:::
84+
85+
### Managing Worktrees
86+
87+
**Viewing Your Worktrees**:
88+
The worktrees list shows:
89+
- Branch name (or "Detached HEAD" if not on a branch)
90+
- Worktree path on your filesystem
91+
- Status indicators (Primary, Locked)
92+
- Current worktree is highlighted
93+
94+
**Deleting Worktrees**:
95+
1. Navigate to Settings → Worktrees
96+
2. Click the trash icon <Codicon name="trash" /> next to the worktree you want to delete
97+
3. Review the warning - deletion will remove:
98+
- The branch and any uncommitted changes
99+
- All files in the worktree directory
100+
4. Confirm deletion
101+
102+
:::warning Deletion is Permanent
103+
Deleting a worktree removes the branch and all files in that directory. Make sure to commit and push any important changes before deleting.
104+
:::
105+
106+
### Copying Files with .worktreeinclude
107+
108+
By default, Git worktrees only include files tracked by Git. Untracked files like `node_modules`, `.env`, or build artifacts aren't copied. The `.worktreeinclude` feature solves this problem.
109+
110+
**How it Works**:
111+
- Create a `.worktreeinclude` file at the root of your repository
112+
- Add patterns for files/directories you want to copy (uses `.gitignore` syntax)
113+
- Files must also be in `.gitignore` to be copied (intersection of both files)
114+
- When creating a new worktree, matching files are automatically copied
115+
116+
**Setting Up .worktreeinclude**:
117+
118+
1. Navigate to Settings → Worktrees
119+
2. If you don't have a `.worktreeinclude` file, you'll see a message at the bottom
120+
3. Click "Create from .gitignore" to automatically create one based on your `.gitignore`
121+
4. Edit the file to include only the patterns you want to copy (e.g., `node_modules`, `.env.local`)
122+
123+
**Example .worktreeinclude**:
124+
```
125+
node_modules
126+
.env.local
127+
.cache
128+
dist
129+
```
130+
131+
:::tip What Gets Copied
132+
Only files that match BOTH `.worktreeinclude` AND `.gitignore` patterns are copied. This ensures you're only copying untracked files that you intentionally want to duplicate across worktrees.
133+
:::
134+
135+
**Copy Progress**:
136+
When creating a worktree with a `.worktreeinclude` file:
137+
- A progress indicator shows which files are being copied
138+
- Large directories like `node_modules` are copied with real-time progress updates
139+
- The operation continues in the background if you close the modal
140+
141+
### Home Screen Integration
142+
143+
The worktree selector can be shown or hidden from the home screen:
144+
145+
1. Navigate to Settings → Worktrees
146+
2. Toggle "Show worktrees in home screen"
147+
3. When enabled, the selector appears at the top of the chat when you have multiple worktrees
148+
4. When disabled, you can still manage worktrees from Settings
149+
150+
---
151+
152+
## Use Cases
153+
154+
### Parallel Feature Development
155+
156+
Create separate worktrees for different features:
157+
- Base worktree on `main` for production hotfixes
158+
- Feature worktree for new development
159+
- Experimental worktree for trying new approaches
160+
161+
Switch between them instantly without stashing or committing incomplete work.
162+
163+
### Code Review Workflow
164+
165+
Review pull requests without disrupting your current work:
166+
1. Create a worktree from the PR branch
167+
2. Open it in a new window
168+
3. Test and review the changes
169+
4. Delete the worktree when done
170+
171+
### Testing Different Implementations
172+
173+
Try multiple solutions to the same problem:
174+
1. Create worktrees for different approaches
175+
2. Run tasks in parallel with Roo Code
176+
3. Compare results
177+
4. Keep the best implementation and delete the others
178+
179+
### Environment Isolation
180+
181+
Maintain separate environments with different dependencies:
182+
- Development worktree with latest dependencies
183+
- Stable worktree with pinned versions
184+
- Testing worktree with experimental packages
185+
186+
Each worktree can have its own `node_modules` copied via `.worktreeinclude`.
187+
188+
---
189+
190+
## Limitations
191+
192+
- **Single-root workspaces only**: Multi-root workspaces are not supported
193+
- **Repository root required**: Workspace must be at the Git repository root, not a subfolder
194+
- **Git required**: Git must be installed on your system
195+
- **Task isolation**: Only one task can run per worktree at a time
196+
- **Branches in use**: Branches already checked out in other worktrees cannot be used for new worktrees
197+
- **Primary worktree**: The original repository worktree (marked as "Primary") cannot be deleted
198+
199+
---
200+
201+
## Tips and Best Practices
202+
203+
- **Organized locations**: Use a consistent location like `~/.roo/worktrees/` for all your worktrees
204+
- **Descriptive branch names**: Use clear naming like `worktree/feature-name` to identify worktree branches
205+
- **Regular cleanup**: Delete worktrees you're no longer using to save disk space
206+
- **Commit before deleting**: Always commit and push important changes before deleting a worktree
207+
- **Use .worktreeinclude**: Set up a `.worktreeinclude` file once and benefit from it for all future worktrees
208+
- **New windows for parallel work**: Open worktrees in new windows when you want to work on multiple branches simultaneously

sidebars.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const sidebars: SidebarsConfig = {
4646
'features/slash-commands',
4747
'features/suggested-responses',
4848
'features/task-todo-list',
49+
'features/worktrees',
4950
'features/shell-integration',
5051
'features/more-features',
5152
],

0 commit comments

Comments
 (0)