Review
Opening the merge request in a worktree
4 min read
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.
- 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….
- Click Open in a worktree… in the review (or in the MR menu).
- The app fetches the MR's head ("Fetching !42…").
- 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."
- Choose the option in Branch in the worktree (table below).
- 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). - Leave Open the worktree in a tab checked to go straight to it.
- 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.
The options that appear depend on what already exists in your repository:
| Option | When it appears | What 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/login | The 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/login | The 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 e5f6a7b8 | Your local branch is behind the MR. | Moves the branch forward to the head and uses it. |
| Create a branch with the name below | Always. | Creates the branch with the name in the New branch name (only for the "name below" option) field. |
| No branch (detached HEAD), just to review | Always. | The worktree stays in detached HEAD, at the MR's head. |
| Field | What it does | Default |
|---|---|---|
| Worktree folder | Where 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 tab | Opens the worktree's tab at the end. | checked |
- "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.
# 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.
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.
- "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
.envandnpm install): Preferences › Worktrees. See Worktrees.
- Worktrees
- MERGE REQUESTS section in the panel (regular branch checkout)
- Checkout