'\" t .\" Title: git-worktree .\" Author: [FIXME: author] [see http://docbook.sf.net/el/author] .\" Generator: DocBook XSL Stylesheets v1.79.1 .\" Date: 06/06/2021 .\" Manual: Git Manual .\" Source: Git 2.30.2 .\" Language: English .\" .TH "GIT\-WORKTREE" "1" "06/06/2021" "Git 2\&.30\&.2" "Git Manual" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .\" http://bugs.debian.org/507673 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" ----------------------------------------------------------------- .\" * set default formatting .\" ----------------------------------------------------------------- .\" disable hyphenation .nh .\" disable justification (adjust text to left margin only) .ad l .\" ----------------------------------------------------------------- .\" * MAIN CONTENT STARTS HERE * .\" ----------------------------------------------------------------- .SH "NAME" git-worktree \- Manage multiple working trees .SH "SYNOPSIS" .sp .nf \fIgit worktree add\fR [\-f] [\-\-detach] [\-\-checkout] [\-\-lock] [\-b ] [] \fIgit worktree list\fR [\-\-porcelain] \fIgit worktree lock\fR [\-\-reason ] \fIgit worktree move\fR \fIgit worktree prune\fR [\-n] [\-v] [\-\-expire ] \fIgit worktree remove\fR [\-f] \fIgit worktree repair\fR [\&...] \fIgit worktree unlock\fR .fi .sp .SH "DESCRIPTION" .sp Manage multiple working trees attached to the same repository\&. .sp A git repository can support multiple working trees, allowing you to check out more than one branch at a time\&. With \fBgit worktree add\fR a new working tree is associated with the repository\&. This new working tree is called a "linked working tree" as opposed to the "main working tree" prepared by \fBgit-init\fR(1) or \fBgit-clone\fR(1)\&. A repository has one main working tree (if it\(cqs not a bare repository) and zero or more linked working trees\&. When you are done with a linked working tree, remove it with \fBgit worktree remove\fR\&. .sp In its simplest form, \fBgit worktree add \fR automatically creates a new branch whose name is the final component of \fB\fR, which is convenient if you plan to work on a new topic\&. For instance, \fBgit worktree add \&.\&./hotfix\fR creates new branch \fBhotfix\fR and checks it out at path \fB\&.\&./hotfix\fR\&. To instead work on an existing branch in a new working tree, use \fBgit worktree add \fR\&. 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 \fIthrowaway\fR working tree not associated with any branch\&. For instance, \fBgit worktree add \-d \fR creates a new working tree with a detached \fBHEAD\fR at the same commit as the current branch\&. .sp If a working tree is deleted without using \fBgit worktree remove\fR, then its associated administrative files, which reside in the repository (see "DETAILS" below), will eventually be removed automatically (see \fBgc\&.worktreePruneExpire\fR in \fBgit-config\fR(1)), or you can run \fBgit worktree prune\fR in the main or any linked working tree to clean up any stale administrative files\&. .sp If a linked working tree 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 \fBgit worktree lock\fR command, optionally specifying \fB\-\-reason\fR to explain why the working tree is locked\&. .SH "COMMANDS" .PP add [] .RS 4 Create \fB\fR and checkout \fB\fR into it\&. The new working directory is linked to the current repository, sharing everything except working directory specific files such as \fBHEAD\fR, \fBindex\fR, etc\&. As a convenience, \fB\fR may be a bare "\fB\-\fR", which is synonymous with \fB@{\-1}\fR\&. .sp If \fB\fR is a branch name (call it \fB\fR) and is not found, and neither \fB\-b\fR nor \fB\-B\fR nor \fB\-\-detach\fR are used, but there does exist a tracking branch in exactly one remote (call it \fB\fR) with a matching name, treat as equivalent to: .sp .if n \{\ .RS 4 .\} .nf $ git worktree add \-\-track \-b / .fi .if n \{\ .RE .\} .sp If the branch exists in multiple remotes and one of them is named by the \fBcheckout\&.defaultRemote\fR configuration variable, we\(cqll use that one for the purposes of disambiguation, even if the \fB\fR isn\(cqt unique across all remotes\&. Set it to e\&.g\&. \fBcheckout\&.defaultRemote=origin\fR to always checkout remote branches from there if \fB\fR is ambiguous but exists on the \fBorigin\fR remote\&. See also \fBcheckout\&.defaultRemote\fR in \fBgit-config\fR(1)\&. .sp If \fB\fR is omitted and neither \fB\-b\fR nor \fB\-B\fR nor \fB\-\-detach\fR used, then, as a convenience, the new working tree is associated with a branch (call it \fB\fR) named after \fB$(basename )\fR\&. If \fB\fR doesn\(cqt exist, a new branch based on \fBHEAD\fR is automatically created as if \fB\-b \fR was given\&. If \fB\fR does exist, it will be checked out in the new working tree, if it\(cqs not checked out anywhere else, otherwise the command will refuse to create the working tree (unless \fB\-\-force\fR is used)\&. .RE .PP list .RS 4 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), and "locked" if the worktree is locked\&. .RE .PP lock .RS 4 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 \fB\-\-reason\fR\&. .RE .PP move .RS 4 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 \fBgit worktree repair\fR command, however, can reestablish the connection with linked working trees if you move the main working tree manually\&.) .RE .PP prune .RS 4 Prune working tree information in \fB$GIT_DIR/worktrees\fR\&. .RE .PP remove .RS 4 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 \fB\-\-force\fR\&. The main working tree cannot be removed\&. .RE .PP repair [\&...] .RS 4 Repair working tree administrative files, if possible, if they have become corrupted or outdated due to external factors\&. .sp For instance, if the main working tree (or bare repository) is moved, linked working trees will be unable to locate it\&. Running \fBrepair\fR in the main working tree will reestablish the connection from linked working trees back to the main working tree\&. .sp Similarly, if a linked working tree is moved without using \fBgit worktree move\fR, the main working tree (or bare repository) will be unable to locate it\&. Running \fBrepair\fR within the recently\-moved working tree will reestablish the connection\&. If multiple linked working trees are moved, running \fBrepair\fR from any working tree with each tree\(cqs new \fB\fR as an argument, will reestablish the connection to all the specified paths\&. .RE .PP unlock .RS 4 Unlock a working tree, allowing it to be pruned, moved or deleted\&. .RE .SH "OPTIONS" .PP \-f, \-\-force .RS 4 By default, \fBadd\fR refuses to create a new working tree when \fB\fR is a branch name and is already checked out by another working tree, or if \fB\fR is already assigned to some working tree but is missing (for instance, if \fB\fR was deleted manually)\&. This option overrides these safeguards\&. To add a missing but locked working tree path, specify \fB\-\-force\fR twice\&. .sp \fBmove\fR refuses to move a locked working tree unless \fB\-\-force\fR is specified twice\&. If the destination is already assigned to some other working tree but is missing (for instance, if \fB\fR was deleted manually), then \fB\-\-force\fR allows the move to proceed; use \fB\-\-force\fR twice if the destination is locked\&. .sp \fBremove\fR refuses to remove an unclean working tree unless \fB\-\-force\fR is used\&. To remove a locked working tree, specify \fB\-\-force\fR twice\&. .RE .PP \-b , \-B .RS 4 With \fBadd\fR, create a new branch named \fB\fR starting at \fB\fR, and check out \fB\fR into the new working tree\&. If \fB\fR is omitted, it defaults to \fBHEAD\fR\&. By default, \fB\-b\fR refuses to create a new branch if it already exists\&. \fB\-B\fR overrides this safeguard, resetting \fB\fR to \fB\fR\&. .RE .PP \-d, \-\-detach .RS 4 With \fBadd\fR, detach \fBHEAD\fR in the new working tree\&. See "DETACHED HEAD" in \fBgit-checkout\fR(1)\&. .RE .PP \-\-[no\-]checkout .RS 4 By default, \fBadd\fR checks out \fB\fR, however, \fB\-\-no\-checkout\fR can be used to suppress checkout in order to make customizations, such as configuring sparse\-checkout\&. See "Sparse checkout" in \fBgit-read-tree\fR(1)\&. .RE .PP \-\-[no\-]guess\-remote .RS 4 With \fBworktree add \fR, without \fB\fR, instead of creating a new branch from \fBHEAD\fR, if there exists a tracking branch in exactly one remote matching the basename of \fB\fR, base the new branch on the remote\-tracking branch, and mark the remote\-tracking branch as "upstream" from the new branch\&. .sp This can also be set up as the default behaviour by using the \fBworktree\&.guessRemote\fR config option\&. .RE .PP \-\-[no\-]track .RS 4 When creating a new branch, if \fB\fR is a branch, mark it as "upstream" from the new branch\&. This is the default if \fB\fR is a remote\-tracking branch\&. See \fB\-\-track\fR in \fBgit-branch\fR(1) for details\&. .RE .PP \-\-lock .RS 4 Keep the working tree locked after creation\&. This is the equivalent of \fBgit worktree lock\fR after \fBgit worktree add\fR, but without a race condition\&. .RE .PP \-n, \-\-dry\-run .RS 4 With \fBprune\fR, do not remove anything; just report what it would remove\&. .RE .PP \-\-porcelain .RS 4 With \fBlist\fR, output in an easy\-to\-parse format for scripts\&. This format will remain stable across Git versions and regardless of user configuration\&. See below for details\&. .RE .PP \-q, \-\-quiet .RS 4 With \fBadd\fR, suppress feedback messages\&. .RE .PP \-v, \-\-verbose .RS 4 With \fBprune\fR, report all removals\&. .RE .PP \-\-expire