add <path> [<commit-ish>]
Create <path>
and checkout <commit-ish>
into it. The new
working directory is linked to the current repository,
sharing everything except working directory specific 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
git-config(1).
If <commit-ish>
is omitted and neither -b
nor -B
nor --detach
used, then, as a convenience, the new working tree is
associated with a branch (call it <branch>
) named after
$(basename <path>)
. If <branch>
doesn't exist, a new branch
based on HEAD
is automatically created as if -b <branch>
was
given. If <branch>
does exist, it will be checked out in the
new working tree, if it's not checked out anywhere else,
otherwise the command will refuse to create the working tree
(unless --force
is used).
list
List details of each working tree. The main working tree is
listed first, followed by each of the linked working trees.
The output details include whether the working tree is bare,
the revision currently checked out, the branch currently
checked out (or "detached HEAD" if none), "locked" if the
worktree is locked, "prunable" if the worktree can be pruned
by prune
command.
lock
If a working tree is on a portable device or network share
which is not always mounted, lock it to prevent its
administrative files from being pruned automatically. This
also prevents it from being moved or deleted. Optionally,
specify a reason for the lock with --reason
.
move
Move a working tree to a new location. Note that the main
working tree or linked working trees containing submodules
cannot be moved with this command. (The git worktree repair
command, however, can reestablish the connection with linked
working trees if you move the main working tree manually.)
prune
Prune working tree information in $GIT_DIR/worktrees
.
remove
Remove a working tree. Only clean working trees (no untracked
files and no modification in tracked files) can be removed.
Unclean working trees or ones with submodules can be removed
with --force
. The main working tree cannot be removed.
repair [<path>...]
Repair working tree administrative files, if possible, if
they have become corrupted or outdated due to external
factors.
For instance, if the main working tree (or bare repository)
is moved, linked working trees will be unable to locate it.
Running repair
in the main working tree will reestablish the
connection from linked working trees back to the main working
tree.
Similarly, if a linked working tree is moved without using
git worktree move
, the main working tree (or bare repository)
will be unable to locate it. Running repair
within the
recently-moved working tree will reestablish the connection.
If multiple linked working trees are moved, running repair
from any working tree with each tree's new <path>
as an
argument, will reestablish the connection to all the
specified paths.
If both the main working tree and linked working trees have
been moved manually, then running repair
in the main working
tree and specifying the new <path>
of each linked working
tree will reestablish all connections in both directions.
unlock
Unlock a working tree, allowing it to be pruned, moved or
deleted.