Skip to content
Latchkey

git worktree: Usage, Options & Common CI Errors

git worktree lets one repository have several working directories, each on a different branch.

Worktrees avoid re-cloning when you need two branches checked out at once - handy for parallel CI builds.

What it does

git worktree creates additional working trees linked to the same repository, so you can have multiple branches checked out simultaneously without separate clones.

Common usage

Terminal
git worktree add ../hotfix hotfix
git worktree add -b release ../release origin/release
git worktree list
git worktree remove ../hotfix
git worktree prune

Options

SubcommandWhat it does
add <path> [<branch>]Create a worktree at path
add -b <new> <path> <ref>Create a branch in a new worktree
listList all worktrees
remove <path>Delete a worktree
pruneClean up stale worktree metadata

Common errors in CI

fatal: 'X' is already checked out at '…' - a branch can be checked out in only one worktree at a time. Use a different branch, or --detach. After deleting a worktree directory manually, run git worktree prune to clear the dangling reference.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →