Git Cheat Sheet · Worktrees

Create a worktree on a new branch

git worktree add -b <branch> <folder>

git worktree add -b <branch> <folder> creates the branch from the current commit, then checks it out in a new folder. Your work in progress stays intact in the original folder, with no stash or branch switch.

What it does

Creates the branch from the current commit, then checks it out in a new folder.

A use case

You are starting hotfix/login from main, while keeping your feature branch open in its folder.

On the command line

git worktree add -b hotfix/login ../site-hotfix
Creates hotfix/login from the current commit, in ../site-hotfix.
git worktree add -b hotfix/login ../site-hotfix main
Starts the new branch from main.
git worktree add -b experiment ../site-experiment <commit>
Starts the new branch from a specific commit.

In Merathon

  1. "Worktrees" section → + button (when hovering the title).
  2. Enter the name of the new branch: it starts from the current branch.
  3. Confirm or change the suggested folder (<repository>-<branch>, next to the repository): it must be absolute and must not exist.
  4. The worktree opens in a new tab.

Frequently asked questions

Where should I put a worktree's folder?

Next to the repository rather than inside it, otherwise it would appear as an untracked folder. Merathon suggests <repository>-<branch>, in the neighboring folder.

What about my submodules?

They are not initialized in a new worktree: run git submodule update --init --recursive from that folder, or initialize them from its tab in Merathon.

See also