By admin , 29 April 2026

Synopsis

git worktree add <path> [<branch>]
git worktree list
git worktree remove <path>
git worktree prune

Description

The git worktree command lets a single repository have multiple working trees checked out simultaneously, each at a different branch. This is faster and cheaper than cloning multiple times: only one object database, but parallel checkouts. Worktrees are perfect for running tests on a release branch while continuing development on main, or for picking up an emergency fix without disturbing in-progress work.

Each worktree has its own HEAD, index, and working files, but shares the underlying objects and config. Locked worktrees prevent automatic pruning of mounted-elsewhere checkouts.

In day-to-day use, git worktree integrates closely with shell aliases, editor plugins, and continuous integration. Power users often add aliases that combine flags they always pass, or wrap the command in scripts that enforce team conventions. Output formatting can be customized via Git config — pretty formats, color schemes, and pager behavior are all tunable. When something goes wrong, the first diagnostic step is usually to re-run the command with GIT_TRACE=1 in the environment, which reveals the underlying plumbing calls. For unusual situations, the --help output (git worktree --help) opens the full manual page with details on every option, including those rarely used in casual workflows but essential for debugging or scripting at scale.

Understanding how git worktree interacts with the rest of Git's data model — the object database, the index, refs, and the working tree — pays dividends. Each command operates on some subset of these pieces, and knowing which it touches helps predict outcomes and recover from mistakes. Reading the official Git documentation alongside hands-on practice in a throwaway repository is the fastest way to internalize the nuances. Most production issues with Git stem from one of three causes: surprising default behavior, partial network operations, or rewriting history that was already shared. A working mental model of git worktree's side effects helps avoid all three.

Common Options

SubcommandDescription
add <path> [<branch>]Create a new worktree.
add -b <new> <path> [<start>]Create new branch + worktree in one step.
listShow all worktrees.
remove <path>Delete a worktree's directory and metadata.
pruneRemove metadata for worktrees whose path is gone.
lock / unlockPrevent or allow pruning.
move <old> <new>Relocate a worktree.

Examples

git worktree add ../project-hotfix release/1.4
# Check out release/1.4 in a sibling directory

git worktree add -b experiment ../project-experiment
# Create a new branch and worktree

git worktree list
# Display all worktrees

git worktree remove ../project-hotfix
# Tear down when finished

Common Mistakes

You cannot have the same branch checked out in two worktrees simultaneously — Git refuses. Use --detach if you only need the contents. Forgetting to worktree remove leaves stale metadata; git worktree prune cleans up.

Related Commands

git switch, git branch, git clone, git submodule