Home Explore Blog CI



git

1st chunk of `Documentation/git-worktree.adoc`
59e5f25ba16bda34f5f333b7696063be579e177c3df9693a0000000100000fa1
git-worktree(1)
===============

NAME
----
git-worktree - Manage multiple working trees


SYNOPSIS
--------
[verse]
'git worktree add' [-f] [--detach] [--checkout] [--lock [--reason <string>]]
		   [--orphan] [(-b | -B) <new-branch>] <path> [<commit-ish>]
'git worktree list' [-v | --porcelain [-z]]
'git worktree lock' [--reason <string>] <worktree>
'git worktree move' <worktree> <new-path>
'git worktree prune' [-n] [-v] [--expire <expire>]
'git worktree remove' [-f] <worktree>
'git worktree repair' [<path>...]
'git worktree unlock' <worktree>

DESCRIPTION
-----------

Manage multiple working trees attached to the same repository.

A git repository can support multiple working trees, allowing you to check
out more than one branch at a time.  With `git worktree add` a new working
tree is associated with the repository, along with additional metadata
that differentiates that working tree from others in the same repository.
The working tree, along with this metadata, is called a "worktree".

This new worktree is called a "linked worktree" as opposed to the "main
worktree" prepared by linkgit:git-init[1] or linkgit:git-clone[1].
A repository has one main worktree (if it's not a bare repository) and
zero or more linked worktrees. When you are done with a linked worktree,
remove it with `git worktree remove`.

In its simplest form, `git worktree add <path>` automatically creates a
new branch whose name is the final component of `<path>`, which is
convenient if you plan to work on a new topic. For instance, `git
worktree add ../hotfix` creates new branch `hotfix` and checks it out at
path `../hotfix`. To instead work on an existing branch in a new worktree,
use `git worktree add <path> <branch>`. On the other hand, if you just
plan to make some experimental changes or do testing without disturbing
existing development, it is often convenient to create a 'throwaway'
worktree not associated with any branch. For instance,
`git worktree add -d <path>` creates a new worktree with a detached `HEAD`
at the same commit as the current branch.

If a working tree is deleted without using `git worktree remove`, then
its associated administrative files, which reside in the repository
(see "DETAILS" below), will eventually be removed automatically (see
`gc.worktreePruneExpire` in linkgit:git-config[1]), or you can run
`git worktree prune` in the main or any linked worktree to clean up any
stale administrative files.

If the working tree for a linked worktree is stored on a portable device
or network share which is not always mounted, you can prevent its
administrative files from being pruned by issuing the `git worktree lock`
command, optionally specifying `--reason` to explain why the worktree is
locked.

COMMANDS
--------
add <path> [<commit-ish>]::

Create a worktree at `<path>` and checkout `<commit-ish>` into it. The new worktree
is linked to the current repository, sharing everything except per-worktree
files such as `HEAD`, `index`, etc. As a convenience, `<commit-ish>` may
be a bare "`-`", which is synonymous with `@{-1}`.
+
If `<commit-ish>` is a branch name (call it `<branch>`) and is not found,
and neither `-b` nor `-B` nor `--detach` are used, but there does
exist a tracking branch in exactly one remote (call it `<remote>`)
with a matching name, treat as equivalent to:
+
------------
$ git worktree add --track -b <branch> <path> <remote>/<branch>
------------
+
If the branch exists in multiple remotes and one of them is named by
the `checkout.defaultRemote` configuration variable, we'll use that
one for the purposes of disambiguation, even if the `<branch>` isn't
unique across all remotes. Set it to
e.g. `checkout.defaultRemote=origin` to always checkout remote
branches from there if `<branch>` is ambiguous but exists on the
`origin` remote. See also `checkout.defaultRemote` in
linkgit:git-config[1].
+
If `<commit-ish>` is omitted and neither `-b` nor `-B` nor `--detach` used,
then, as a convenience, the new worktree is associated with a

Title: Git Worktree Management
Summary
The git-worktree command is used to manage multiple working trees attached to the same repository, allowing for the checkout of more than one branch at a time and providing various options for adding, listing, locking, moving, pruning, and removing worktrees.