Worktrees
Create and open worktrees
9 min read
This page covers how a worktree comes in: creating the folder, opening the tab and working in it. Versora also links the new worktree to the repository it came from. The tabs are grouped, the graph inherits the hidden and solo branches, and the terminal follows the folder switch.
It's the most complete path. You choose where the worktree starts from (the current branch, another branch or the current commit), whether it gets a new branch, where the folder goes and whether it opens in a tab.
- Left panel: the + button in the WORKTREES section header (tooltip "New worktree…").
- Palette (Ctrl+P): "New worktree…" (detail: "Another working folder of this repository, on a branch").
- Open the repository in a tab and click the + in the WORKTREES section.
- In the New worktree window, choose in Start from:
- "‹branch› (current branch)": the branch checked out in this tab;
- "Current commit (‹sha›)": the commit you're on;
- any other local branch on the list.
- In New branch, type a name (for example
fix/erro-no-login) to create the branch right away. If you leave it empty, the worktree uses the chosen branch itself. If you chose the current commit and left it empty, the worktree is in detached HEAD. - Check Folder to create it in. The default is the folder that contains the repository, so the worktree sits next to it.
- Check Folder name. The default is the repository's name with
-wtat the end (for exampleloja-web-wt). - Leave Open in a new tab checked to start working in the worktree right afterwards.
- Click Create worktree.
| Option | What it does | Default |
|---|---|---|
| Start from | The branch or commit the worktree starts from. | The current branch (or the current commit, in detached HEAD) |
| New branch | Creates a branch with that name at the chosen point and checks it out in the new folder. | Empty: uses the chosen branch (or detached HEAD on the commit) |
| Folder to create it in | The folder in which the worktree's folder will be created. | The folder that contains the repository |
| Folder name | The worktree folder's name. | <repository>-wt |
| Open in a new tab | Opens the worktree in a tab as soon as it's created. Unchecked, the app only says "Worktree created at ‹folder›." | Checked |
When you're already looking at the branch or the commit in the graph, the context menu creates the worktree straight from it.
- The commit's menu (right-click a commit in the graph): Create worktree from this commit…
- A local branch's menu (in the left panel or on the graph label): Create worktree from › ‹branch› or Create worktree from › this commit. The item with the branch's name is disabled on the current branch, because it's already checked out here.
- A remote branch's menu: Create worktree from › origin/‹branch› or › this commit.
- Right-click the commit or the branch and choose the item above.
- The Create worktree window says where it starts from ("A second working folder for this repository, starting at ‹point›. It opens in a new tab.").
- In Create in, choose the folder where the worktree will live.
- Check Folder name. The default is
<repository>-<branch>, with the slashes in the branch's name replaced with hyphens (feature/loginbecomesloja-web-feature-login), or<repository>-<short sha>for a commit. - In New branch (optional), type a name if you want a new branch. Empty, the worktree uses the branch itself or, for a commit, is in detached HEAD.
- Click Create worktree. The worktree's tab opens on its own.
Tip
When creating from a remote branch (origin/feature/login), fill in New
branch (optional) with the local name (feature/login). Without it, git leaves the worktree in
detached HEAD on the remote's commit, and a commit made there isn't on any branch.
Both windows run the same command, in the active tab's repository:
# with a new branch
git worktree add -b fix/erro-no-login ../loja-web-wt main
# without a new branch: uses the chosen branch (or detached HEAD, if it's a commit)
git worktree add ../loja-web-wt feature/login
The repository gets an entry in .git/worktrees/ and the new folder gets a .git file pointing to
it. No existing branch changes. With New branch, a branch is created at the chosen point.
Right afterwards, Versora:
- copies the source repository's graph filter to the new worktree (see "The graph view comes along", below);
- opens the Prepare the worktree window, if the repository has a
.worktreeincludethat picks files or saved setup commands. Without any of that, the window doesn't even show up. See Prepare the new worktree.
The same goes for worktrees created from a merge request, through the in-app review (see MR review).
Creating a worktree doesn't go into Ctrl+Z. To go back, remove the worktree (and the branch, if it was created just for it): see Remove, lock and unlock.
- "The branch ‹branch› is already checked out here or in another worktree. Give it a new branch name.": git doesn't allow the same branch in two folders. Fill in New branch or choose another starting point.
- Create inside this worktree? ("The folder ‹folder› is inside this worktree's folder: it will
show up as untracked files here unless it's in .gitignore."): you chose a folder inside the
repository itself. Click Create anyway only if that folder is in
.gitignore. The usual thing is to create the worktree next to the repository. - "The folder already exists: ‹folder›": there's already a folder with that name at the destination. Change the Folder name.
- "Worktree created at ‹folder›." (or "Worktree created at ‹folder›", from the commit/branch menu): it worked.
The left panel's WORKTREES section lists the repository's other worktrees. The number next to the title counts how many there are. With none, it shows "No other worktrees. Create one from a commit or branch menu."
Each row shows the folder's name and the checked-out branch (or "detached HEAD"), plus the markers:
| Marker | Meaning |
|---|---|
| ●3 | The worktree has 3 uncommitted changes (tooltip: "3 uncommitted changes"). |
| Padlock | The worktree is locked. The tooltip shows "Locked" or "Locked: ‹reason›". |
| folder missing | The folder no longer exists (tooltip: "This worktree's folder no longer exists. Remove it to clean up the record."). |
Hover to see the full path and the tooltip "Double-click to open in a tab". A double-click opens the worktree in a tab (or activates the tab, if it's already open).
Right-click a row in the section:
| Item | What it does |
|---|---|
| Open in a tab | Opens or activates the worktree's tab. |
| Show in file explorer | Opens the folder in File Explorer. |
| Copy path | Copies the folder's path ("Path copied"). |
| Open the terminal in this worktree | Opens the worktree's tab with the integrated terminal in its folder. |
| Bring the changes over here… | Brings the uncommitted changes from that worktree to the current tab. See Move changes and commits. |
| Send the changes from here to there… | Takes the uncommitted changes from the current tab to that worktree. Disabled if the current tab has no changes. |
| Prepare (.worktreeinclude and setup)… | Opens the prepare window for that worktree. See Prepare the new worktree. |
| Lock worktree… / Unlock worktree | See Remove, lock and unlock. |
| Remove this worktree… | Removes the worktree's folder, with a check of what would be lost. |
| Remove worktree and delete branch ‹branch›… | Removes the folder and the local branch together. It only shows up if the worktree is on a branch. |
The items that depend on the folder are disabled when it's missing.
When a branch is checked out in another worktree, its menu gets three items:
- Open this branch's worktree (‹folder›);
- Remove this branch's worktree…;
- Remove worktree and delete branch ‹branch›….
The repository's tabs and those of its worktrees sit side by side, with a band of the same color underneath. A linked worktree's tab carries the worktree icon, with the tooltip "Worktree of the ‹name› repository". In the vertical tabs, the worktrees show up indented under the repository's tab.
Grouping changes the real order of the tabs. That's why Ctrl+1 to Ctrl+9, Ctrl+Tab and the vertical tabs follow the same order you see. Dragging a tab out of the group takes the whole group.
To turn it off: Preferences › Worktrees › Grouped tabs, the "Group worktree tabs of the same repository" checkbox.
A new worktree inherits the graph view of the repository it was created from: the hidden branches and the solo branches. That applies to every way of creating it (the section's "+", the branch's and the commit's menu, and the worktree opened from an MR). There are two adjustments:
- the worktree's own branch is never hidden;
- if the source had solo branches, the worktree's branch goes into solo too. Without that, the new graph wouldn't show its own work.
After that, each tab has its own filter. Changing the filter in one tab doesn't change the other. See Graph search and filters.
Each worktree has its own integrated terminals, open in its folder. With the terminal open, switching to the tab of another worktree of the same repository shows that worktree's terminal. If it doesn't have a terminal yet, the app opens a new one in its folder. The keyboard focus goes along when it was in the terminal.
This only touches the app's own terminals. To turn it off: Preferences › Worktrees › Terminal, the "The terminal follows worktree switches" checkbox. See also Integrated terminal.
In a repository with many branches, a worktree's graph can show only what belongs to it: the history of the checked-out branch and of that branch's upstream.
- The target button in the WORKTREES section header. The tooltip says "Show only this worktree in the graph (‹branch› and its upstream)" when it's off and "Show all branches in the graph" when it's on.
- Palette (Ctrl+P): "Graph: only this worktree" (detail: "Only the history of ‹branch› and its upstream") or "Graph: show all branches".
- In the worktree's tab, click the target button in the WORKTREES header.
- The graph then shows only the worktree's branch and its upstream, in solo.
- Click again to go back to the filter you had before.
The scope follows the worktree: if you check out another branch in that tab, the graph then shows the new branch. Changing the filter by hand (a branch's eye, solo or the palette's "Show all branches in the graph" command) ends the scope and keeps the filter you chose.
- "This worktree is in detached HEAD: the scope needs a branch.": the button is disabled without a branch. Check out a branch first.
-
Preferences › Worktrees ("Tabs, graph and terminal" group):
Setting Checkbox Default Grouped tabs Group worktree tabs of the same repository On Worktree WIP in the graph Show a WIP row for each worktree On Terminal The terminal follows worktree switches On These three settings apply to the whole app, on this computer. The setup commands, on the same page, apply per repository: see Prepare the new worktree.
-
The administrator can hide the Worktrees page in Preferences or make it read-only, with the
preferences_hiddenandpreferences_lockedkeys and theworktreesid. See Policy keys.
- Prepare the new worktree
- Each worktree's WIP in the graph
- Graph context menus
- Tabs
- Official documentation: git worktree (opens another site)