Git Cheat Sheet · Worktrees

Check out an existing branch in a worktree

git worktree add <folder> <branch>

git worktree add <folder> <branch> checks out an existing local branch in a new folder. You stay on your branch where you are, and you can run or review the other one alongside it.

What it does

Checks out an already created local branch in a new folder, without changing branch where you are.

A use case

A colleague asks you to review their feature/export branch while you work on another: you run it alongside to compare the two.

On the command line

git worktree add ../site-export feature/export
Checks out feature/export in ../site-export.
git worktree add --track -b feature/export ../site-export origin/feature/export
Creates the local branch from the remote branch, and checks it out.
git worktree add --detach ../site-v1 v1.0
Checks out a tag or a commit, with no branch.

In Merathon

  1. Right-click the branch, in the "Local" section or the graph.
  2. Choose "Check out in a new worktree…".
  3. Confirm or change the suggested folder.

Frequently asked questions

Why "fatal: 'main' is already used by worktree"?

This branch is already checked out in another worktree, and a branch can only be in one place. git worktree list shows which one.

Can I check out a remote branch directly?

Git expects a local branch. If the name exists on only one remote, git worktree add <folder> <name> creates the local branch that tracks it; otherwise, specify it with --track -b.

See also