Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/Documentation/git-worktree.adoc # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / Documentation / git-worktree.adoc` 549 lines ยท 22045 bytes Raw Blame History 1 git-worktree(1) 2 =============== 3 4 NAME 5 ---- 6 git-worktree - Manage multiple working trees 7 8 9 SYNOPSIS 10 -------- 11 [synopsis] 12 git worktree add [-f] [--detach] [--checkout] [--lock [--reason ]] 13 [--orphan] [(-b | -B) ] [] 14 git worktree list [-v | --porcelain [-z]] 15 git worktree lock [--reason ] 16 git worktree move 17 git worktree prune [-n] [-v] [--expire ] 18 git worktree remove [-f] 19 git worktree repair [...] 20 git worktree unlock 21 22 DESCRIPTION 23 ----------- 24 25 Manage multiple working trees attached to the same repository. 26 27 A git repository can support multiple working trees, allowing you to check 28 out more than one branch at a time. With `git worktree add` a new working 29 tree is associated with the repository, along with additional metadata 30 that differentiates that working tree from others in the same repository. 31 The working tree, along with this metadata, is called a "worktree". 32 33 This new worktree is called a "linked worktree" as opposed to the "main 34 worktree" prepared by linkgit:git-init[1] or linkgit:git-clone[1]. 35 A repository has one main worktree (if it's not a bare repository) and 36 zero or more linked worktrees. When you are done with a linked worktree, 37 remove it with `git worktree remove`. 38 39 In its simplest form, `git worktree add ` automatically creates a 40 new branch whose name is the final component of __, which is 41 convenient if you plan to work on a new topic. For instance, `git 42 worktree add ../hotfix` creates new branch `hotfix` and checks it out at 43 path `../hotfix`. To instead work on an existing branch in a new worktree, 44 use `git worktree add `. On the other hand, if you just 45 plan to make some experimental changes or do testing without disturbing 46 existing development, it is often convenient to create a 'throwaway' 47 worktree not associated with any branch. For instance, 48 `git worktree add -d ` creates a new worktree with a detached `HEAD` 49 at the same commit as the current branch. 50 51 If a working tree is deleted without using `git worktree remove`, then 52 its associated administrative files, which reside in the repository 53 (see <> below), will eventually be removed automatically 54 (see `gc.worktreePruneExpire` in linkgit:git-config[1]), or you can run 55 `git worktree prune` in the main or any linked worktree to clean up any 56 stale administrative files. 57 58 If the working tree for a linked worktree is stored on a portable device 59 or network share which is not always mounted, you can prevent its 60 administrative files from being pruned by issuing the `git worktree lock` 61 command, optionally specifying `--reason` to explain why the worktree is 62 locked. 63 64 COMMANDS 65 -------- 66 `add []`:: 67 68 Create a worktree at __ and checkout __ into it. The new worktree 69 is linked to the current repository, sharing everything except per-worktree 70 files such as `HEAD`, `index`, etc. As a convenience, __ may 71 be a bare "`-`", which is synonymous with `@{-1}`. 72 + 73 If __ is a branch name (call it __) and is not found, 74 and neither `-b` nor `-B` nor `--detach` are used, but there does 75 exist a tracking branch in exactly one remote (call it __) 76 with a matching name, treat as equivalent to: 77 + 78 ------------ 79 $ git worktree add --track -b / 80 ------------ 81 + 82 If the branch exists in multiple remotes and one of them is named by 83 the `checkout.defaultRemote` configuration variable, we'll use that 84 one for the purposes of disambiguation, even if the __ isn't 85 unique across all remotes. Set it to 86 e.g. `checkout.defaultRemote=origin` to always checkout remote 87 branches from there if __ is ambiguous but exists on the 88 `origin` remote. See also `checkout.defaultRemote` in 89 linkgit:git-config[1]. 90 + 91 If __ is omitted and neither `-b` nor `-B` nor `--detach` used, 92 then, as a convenience, the new worktree is associated with a branch (call 93 it __) named after `$(basename )`. If __ doesn't 94 exist, a new branch based on `HEAD` is automatically created as if 95 `-b ` was given. If __ does exist, it will be checked out 96 in the new worktree, if it's not checked out anywhere else, otherwise the 97 command will refuse to create the worktree (unless `--force` is used). 98 + 99 If __ is omitted, neither `--detach`, or `--orphan` is 100 used, and there are no valid local branches (or remote branches if 101 `--guess-remote` is specified) then, as a convenience, the new worktree is 102 associated with a new unborn branch named __ (after 103 `$(basename )` if neither `-b` or `-B` is used) as if `--orphan` was 104 passed to the command. In the event the repository has a remote and 105 `--guess-remote` is used, but no remote or local branches exist, then the 106 command fails with a warning reminding the user to fetch from their remote 107 first (or override by using `-f`/`--force`). 108 109 `list`:: 110 111 List details of each worktree. The main worktree is listed first, 112 followed by each of the linked worktrees. The output details include 113 whether the worktree is bare, the revision currently checked out, the 114 branch currently checked out (or "detached HEAD" if none), "locked" if 115 the worktree is locked, "prunable" if the worktree can be pruned by the 116 `prune` command. 117 118 `lock`:: 119 120 If a worktree is on a portable device or network share which is not always 121 mounted, lock it to prevent its administrative files from being pruned 122 automatically. This also prevents it from being moved or deleted. 123 Optionally, specify a reason for the lock with `--reason`. 124 125 `move`:: 126 127 Move a worktree to a new location. Note that the main worktree or linked 128 worktrees containing submodules cannot be moved with this command. (The 129 `git worktree repair` command, however, can reestablish the connection 130 with linked worktrees if you move the main worktree manually.) 131 132 `prune`:: 133 134 Remove worktree information in `$GIT_DIR/worktrees` for worktrees 135 whose working trees are missing. Useful after manually removing 136 a working tree that is no longer needed (but use "git worktree 137 remove" next time you want to do so). Also, if you _moved_ a 138 working tree elsewhere causing the worktree information to become 139 dangling, see "git worktree repair" to reconnect the worktree to 140 the new working tree location. 141 142 `remove`:: 143 144 Remove a worktree. Only clean worktrees (no untracked files and no 145 modification in tracked files) can be removed. Unclean worktrees or ones 146 with submodules can be removed with `--force`. The main worktree cannot be 147 removed. 148 149 `repair [...]`:: 150 151 Repair worktree administrative files, if possible, if they have become 152 corrupted or outdated due to external factors. 153 + 154 For instance, if the main worktree (or bare repository) is moved, linked 155 worktrees will be unable to locate it. Running `repair` in the main 156 worktree will reestablish the connection from linked worktrees back to the 157 main worktree. 158 + 159 Similarly, if the working tree for a linked worktree is moved without 160 using `git worktree move`, the main worktree (or bare repository) will be 161 unable to locate it. Running `repair` within the recently-moved worktree 162 will reestablish the connection. If multiple linked worktrees are moved, 163 running `repair` from any worktree with each tree's new __ as an 164 argument, will reestablish the connection to all the specified paths. 165 + 166 If both the main worktree and linked worktrees have been moved or copied manually, 167 then running `repair` in the main worktree and specifying the new __ 168 of each linked worktree will reestablish all connections in both 169 directions. 170 171 `unlock`:: 172 173 Unlock a worktree, allowing it to be pruned, moved or deleted. 174 175 OPTIONS 176 ------- 177 178 `-f`:: 179 `--force`:: 180 By default, `add` refuses to create a new worktree when 181 __ is a branch name and is already checked out by 182 another worktree, or if __ is already assigned to some 183 worktree but is missing (for instance, if __ was deleted 184 manually). This option overrides these safeguards. To add a missing but 185 locked worktree path, specify `--force` twice. 186 + 187 `move` refuses to move a locked worktree unless `--force` is specified 188 twice. If the destination is already assigned to some other worktree but is 189 missing (for instance, if __ was deleted manually), then `--force` 190 allows the move to proceed; use `--force` twice if the destination is locked. 191 + 192 `remove` refuses to remove an unclean worktree unless `--force` is used. 193 To remove a locked worktree, specify `--force` twice. 194 195 `-b `:: 196 `-B `:: 197 With `add`, create a new branch named __ starting at 198 __, and check out __ into the new worktree. 199 If __ is omitted, it defaults to `HEAD`. 200 By default, `-b` refuses to create a new branch if it already 201 exists. `-B` overrides this safeguard, resetting __ to 202 __. 203 204 `-d`:: 205 `--detach`:: 206 With `add`, detach `HEAD` in the new worktree. See "DETACHED HEAD" 207 in linkgit:git-checkout[1]. 208 209 `--checkout`:: 210 `--no-checkout`:: 211 By default, `add` checks out __, however, `--no-checkout` can 212 be used to suppress checkout in order to make customizations, 213 such as configuring sparse-checkout. See "Sparse checkout" 214 in linkgit:git-read-tree[1]. 215 216 `--guess-remote`:: 217 `--no-guess-remote`:: 218 With `worktree add `, without __, instead 219 of creating a new branch from `HEAD`, if there exists a tracking 220 branch in exactly one remote matching the basename of __, 221 base the new branch on the remote-tracking branch, and mark 222 the remote-tracking branch as "upstream" from the new branch. If 223 there are multiple matches, the command fails. If there is no 224 match, the command falls back to creating a new branch from `HEAD`. 225 + 226 This can also be set up as the default behaviour by using the 227 `worktree.guessRemote` config option. 228 229 `--relative-paths`:: 230 `--no-relative-paths`:: 231 Link worktrees using relative paths or absolute paths (default). 232 Overrides the `worktree.useRelativePaths` config option, see 233 linkgit:git-config[1]. 234 + 235 With `repair`, the linking files will be updated if there's an absolute/relative 236 mismatch, even if the links are correct. 237 238 `--track`:: 239 `--no-track`:: 240 When creating a new branch, if __ is a branch, 241 mark it as "upstream" from the new branch. This is the 242 default if __ is a remote-tracking branch. See 243 `--track` in linkgit:git-branch[1] for details. 244 245 `--lock`:: 246 Keep the worktree locked after creation. This is the 247 equivalent of `git worktree lock` after `git worktree add`, 248 but without a race condition. 249 250 `-n`:: 251 `--dry-run`:: 252 With `prune`, do not remove anything; just report what it would 253 remove. 254 255 `--orphan`:: 256 With `add`, make the new worktree and index empty, associating 257 the worktree with a new unborn branch named __. 258 259 `--porcelain`:: 260 With `list`, output in an easy-to-parse format for scripts. 261 This format will remain stable across Git versions and regardless of user 262 configuration. It is recommended to combine this with `-z`. 263 See below for details. 264 265 `-z`:: 266 Terminate each line with a _NUL_ rather than a newline when 267 `--porcelain` is specified with `list`. This makes it possible 268 to parse the output when a worktree path contains a newline 269 character. 270 271 `-q`:: 272 `--quiet`:: 273 With `add`, suppress feedback messages. 274 275 `-v`:: 276 `--verbose`:: 277 With `prune`, report all removals. 278 + 279 With `list`, output additional information about worktrees (see below). 280 281 `--expire