Skip to content
Versora

Manual

Review

Opening the merge request in a worktree

4 min read

On this page

To run a merge request's code (build, test, open it in the editor) without dropping what you're doing, open the MR in a worktree: a second working folder of the same repository, with the MR's head checked out. Your current folder, your branch and your uncommitted changes stay as they are. It also works with an MR from a fork, which a regular checkout can't bring in.

Where to find it

  • Review header › Open in a worktree… button (worktree icon, next to "Open in browser").
  • MERGE REQUESTS section in the panel › MR menu › Open in a worktree….

Step by step

  1. Click Open in a worktree… in the review (or in the MR menu).
  2. The app fetches the MR's head ("Fetching !42…").
  3. In the Open !42 in a worktree dialog, read the summary: "The worktree goes in a new folder, at commit a1b2c3d4 of feature/login. The current folder doesn't change."
  4. Choose the option in Branch in the worktree (table below).
  5. Check the Worktree folder. The default is a new folder next to the repository, with the MR number: app-mr-42 (on GitHub, app-pr-42).
  6. Leave Open the worktree in a tab checked to go straight to it.
  7. Click Create worktree. The bar shows "Creating the worktree for !42…" and, at the end, "Worktree for !42 created at D:/projetos/app-mr-42.".

The worktree tab opens next to the repository tab, grouped with it. See Worktrees.

Branch in the worktree

The options that appear depend on what already exists in your repository:

OptionWhen it appearsWhat it does
Open the existing worktree (path)There's already a worktree at this head.Just opens its tab; nothing is created.
Create branch feature/login, tracking origin/feature/loginThe branch doesn't exist here.Creates the branch at the MR's head, already tracking the source one: pull and push work without configuring anything.
Create branch mr-42-feature/loginThe MR is from a fork (or the branch is gone from the server).Creates the branch without an upstream (a push wouldn't go to the fork).
Use branch feature/login (already at this head)Your local branch is already the same as the MR.Uses the branch as it is.
Use branch feature/login, fast-forwarding from a1b2c3d4 to e5f6a7b8Your local branch is behind the MR.Moves the branch forward to the head and uses it.
Create a branch with the name belowAlways.Creates the branch with the name in the New branch name (only for the "name below" option) field.
No branch (detached HEAD), just to reviewAlways.The worktree stays in detached HEAD, at the MR's head.

Other fields

FieldWhat it doesDefault
Worktree folderWhere the worktree is created. It must be a full path and a folder that doesn't exist yet.<repository>-mr-<number> next to the repository
New branch name (only for the "name below" option)The name used in "Create a branch with the name below".mr-42-feature/login (a free name, if that one already exists)
Open the worktree in a tabOpens the worktree's tab at the end.checked

Dialog warnings

  • "The merge request comes from a fork: the head came from the special ref refs/merge-requests/42/head." (on GitHub, refs/pull/42/head).
  • "The source branch is no longer on the server: the head came from the special ref …".
  • "The fetched head (e5f6a7b8) differs from the one the server reported (a1b2c3d4): the branch may have just received commits.".
  • "This folder is already at this head.".
  • "Branch feature/login is already checked out in D:/projetos/app-2: choose another name or detached HEAD.".
  • "Local branch feature/login has commits outside the merge request: it won't be used or touched." The app offers to create another name.

What Versora does in git

bash
# 1. the MR's head: the source branch…
git fetch --no-tags --no-write-fetch-head origin +refs/heads/feature/login:refs/remotes/origin/feature/login
# …or, from a fork or with the branch deleted, the server's special ref
git fetch --no-tags --no-write-fetch-head origin +refs/merge-requests/42/head:refs/versora/fork/42

# 2. the worktree, according to the option
git worktree add -b feature/login D:/projetos/app-mr-42 a1b2c3d4
git branch --set-upstream-to=origin/feature/login feature/login
# (detached HEAD)
git worktree add --detach D:/projetos/app-mr-42 a1b2c3d4

The refs/versora/fork/42 ref is internal to Versora: it doesn't appear as a branch and isn't pushed.

How to undo

Creating the worktree isn't part of Ctrl+Z. To undo it, use Remove this worktree… in the worktree's menu, in the WORKTREES section of the left panel. The dialog's note says so: "To undo, use "Remove this worktree…" in the left panel (the branch created stays in the repository)." See Worktrees.

Caveats and messages

  • "Choose a folder with its full path (got: app-mr-42).": use the choose-folder button or type the whole path.
  • "The folder already exists: D:/projetos/app-mr-42": choose another folder.
  • "Branch feature/login already exists: choose another name or use the existing branch.".
  • "Invalid branch name: …".
  • "The worktree was created, but branch feature/login couldn't be set to track origin/feature/login: …": set the upstream later (see Upstream).
  • "The worktree was created, but the fast-forward of branch feature/login failed: …".
  • "Couldn't fetch refs/merge-requests/42/head from remote origin: …": check the network and the server credential.
  • Files and setup commands for a new worktree (such as .env and npm install): Preferences › Worktrees. See Worktrees.

See also