'\" t .\" Title: git-worktree .\" Author: [FIXME: author] [see http://www.docbook.org/tdg5/en/html/author] .\" Generator: DocBook XSL Stylesheets vsnapshot .\" Date: 11/27/2023 .\" Manual: Git Manual .\" Source: Git 2.43.0 .\" Language: English .\" .TH "GIT\-WORKTREE" "1" "11/27/2023" "Git 2\&.43\&.0" "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 [\-\-reason ]] [\-\-orphan] [(\-b | \-B) ] [] \fIgit worktree list\fR [\-v | \-\-porcelain [\-z]] \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, 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"\&. .sp This new worktree is called a "linked worktree" as opposed to the "main worktree" prepared by \fBgit-init\fR(1) or \fBgit-clone\fR(1)\&. A repository has one main worktree (if it\(cqs not a bare repository) and zero or more linked worktrees\&. When you are done with a linked worktree, 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 worktree, 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 worktree not associated with any branch\&. For instance, \fBgit worktree add \-d \fR creates a new worktree 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 worktree to clean up any stale administrative files\&. .sp 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 \fBgit worktree lock\fR command, optionally specifying \fB\-\-reason\fR to explain why the worktree is locked\&. .SH "COMMANDS" .PP add [] .RS 4 Create a worktree at \fB\fR and checkout \fB\fR into it\&. The new worktree is linked to the current repository, sharing everything except per\-worktree 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 worktree 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 worktree, if it\(cqs not checked out anywhere else, otherwise the command will refuse to create the worktree (unless \fB\-\-force\fR is used)\&. .sp If \fB\fR is omitted, neither \fB\-\-detach\fR, or \fB\-\-orphan\fR is used, and there are no valid local branches (or remote branches if \fB\-\-guess\-remote\fR is specified) then, as a convenience, the new worktree is associated with a new orphan branch named \fB\fR (after \fB$(basename )\fR if neither \fB\-b\fR or \fB\-B\fR is used) as if \fB\-\-orphan\fR was passed to the command\&. In the event the repository has a remote and \fB\-\-guess\-remote\fR is used, but no remote or local branches exist, then the command fails with a warning reminding the user to fetch from their remote first (or override by using \fB\-f/\-\-force\fR)\&. .RE .PP list .RS 4 List details of each worktree\&. The main worktree is listed first, followed by each of the linked worktrees\&. The output details include whether the worktree 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 the \fBprune\fR command\&. .RE .PP lock .RS 4 If a worktree 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 worktree to a new location\&. Note that the main worktree or linked worktrees containing submodules cannot be moved with this command\&. (The \fBgit worktree repair\fR command, however, can reestablish the connection with linked worktrees if you move the main worktree manually\&.) .RE .PP prune .RS 4 Prune worktree information in \fB$GIT_DIR/worktrees\fR\&. .RE .PP remove .RS 4 Remove a worktree\&. Only clean worktrees (no untracked files and no modification in tracked files) can be removed\&. Unclean worktrees or ones with submodules can be removed with \fB\-\-force\fR\&. The main worktree cannot be removed\&. .RE .PP repair [\&...] .RS 4 Repair worktree administrative files, if possible, if they have become corrupted or outdated due to external factors\&. .sp For instance, if the main worktree (or bare repository) is moved, linked worktrees will be unable to locate it\&. Running \fBrepair\fR in the main worktree will reestablish the connection from linked worktrees back to the main worktree\&. .sp Similarly, if the working tree for a linked worktree is moved without using \fBgit worktree move\fR, the main worktree (or bare repository) will be unable to locate it\&. Running \fBrepair\fR within the recently\-moved worktree will reestablish the connection\&. If multiple linked worktrees are moved, running \fBrepair\fR from any worktree with each tree\(cqs new \fB\fR as an argument, will reestablish the connection to all the specified paths\&. .sp If both the main worktree and linked worktrees have been moved manually, then running \fBrepair\fR in the main worktree and specifying the new \fB\fR of each linked worktree will reestablish all connections in both directions\&. .RE .PP unlock .RS 4 Unlock a worktree, 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 worktree when \fB\fR is a branch name and is already checked out by another worktree, or if \fB\fR is already assigned to some worktree but is missing (for instance, if \fB\fR was deleted manually)\&. This option overrides these safeguards\&. To add a missing but locked worktree path, specify \fB\-\-force\fR twice\&. .sp \fBmove\fR refuses to move a locked worktree unless \fB\-\-force\fR is specified twice\&. If the destination is already assigned to some other worktree 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 worktree unless \fB\-\-force\fR is used\&. To remove a locked worktree, 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 worktree\&. 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 worktree\&. 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 worktree 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 \-\-orphan .RS 4 With \fBadd\fR, make the new worktree and index empty, associating the worktree with a new orphan/unborn branch named \fB\fR\&. .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\&. It is recommended to combine this with \fB\-z\fR\&. See below for details\&. .RE .PP \-z .RS 4 Terminate each line with a NUL rather than a newline when \fB\-\-porcelain\fR is specified with \fBlist\fR\&. This makes it possible to parse the output when a worktree path contains a newline character\&. .RE .PP \-q, \-\-quiet .RS 4 With \fBadd\fR, suppress feedback messages\&. .RE .PP \-v, \-\-verbose .RS 4 With \fBprune\fR, report all removals\&. .sp With \fBlist\fR, output additional information about worktrees (see below)\&. .RE .PP \-\-expire