]>
Commit | Line | Data |
---|---|---|
df0b6cfb NTND |
1 | git-worktree(1) |
2 | =============== | |
3 | ||
4 | NAME | |
5 | ---- | |
bc483285 | 6 | git-worktree - Manage multiple working trees |
df0b6cfb NTND |
7 | |
8 | ||
9 | SYNOPSIS | |
10 | -------- | |
11 | [verse] | |
5af8b61c ÆAB |
12 | 'git worktree add' [-f] [--detach] [--checkout] [--lock [--reason <string>]] |
13 | [-b <new-branch>] <path> [<commit-ish>] | |
d97eb302 | 14 | 'git worktree list' [-v | --porcelain [-z]] |
58142c09 | 15 | 'git worktree lock' [--reason <string>] <worktree> |
9f792bb4 | 16 | 'git worktree move' <worktree> <new-path> |
7b722d90 | 17 | 'git worktree prune' [-n] [-v] [--expire <expire>] |
d228eea5 | 18 | 'git worktree remove' [-f] <worktree> |
b214ab5a | 19 | 'git worktree repair' [<path>...] |
6d308627 | 20 | 'git worktree unlock' <worktree> |
df0b6cfb NTND |
21 | |
22 | DESCRIPTION | |
23 | ----------- | |
24 | ||
bc483285 | 25 | Manage multiple working trees attached to the same repository. |
df0b6cfb | 26 | |
93a36493 | 27 | A git repository can support multiple working trees, allowing you to check |
4d5a3c58 | 28 | out more than one branch at a time. With `git worktree add` a new working |
c57bf8ce DS |
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`. | |
93a36493 | 38 | |
dccadad7 ES |
39 | In its simplest form, `git worktree add <path>` automatically creates a |
40 | new branch whose name is the final component of `<path>`, 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 | |
c57bf8ce DS |
43 | path `../hotfix`. To instead work on an existing branch in a new worktree, |
44 | use `git worktree add <path> <branch>`. 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 <path>` creates a new worktree with a detached `HEAD` | |
49 | at the same commit as the current branch. | |
dccadad7 | 50 | |
3f0b42bd ES |
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 "DETAILS" below), will eventually be removed automatically (see | |
5f5f553f | 54 | `gc.worktreePruneExpire` in linkgit:git-config[1]), or you can run |
c57bf8ce DS |
55 | `git worktree prune` in the main or any linked worktree to clean up any |
56 | stale administrative files. | |
93a36493 | 57 | |
c57bf8ce DS |
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. | |
93a36493 | 63 | |
df0b6cfb NTND |
64 | COMMANDS |
65 | -------- | |
c4738aed | 66 | add <path> [<commit-ish>]:: |
fc56361f | 67 | |
c57bf8ce DS |
68 | Create a worktree at `<path>` and checkout `<commit-ish>` 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, `<commit-ish>` may | |
71 | be a bare "`-`", which is synonymous with `@{-1}`. | |
1eb07d82 | 72 | + |
e79e313c | 73 | If `<commit-ish>` is a branch name (call it `<branch>`) and is not found, |
4e853331 TG |
74 | and neither `-b` nor `-B` nor `--detach` are used, but there does |
75 | exist a tracking branch in exactly one remote (call it `<remote>`) | |
661a5a38 | 76 | with a matching name, treat as equivalent to: |
d023df1e | 77 | + |
4e853331 TG |
78 | ------------ |
79 | $ git worktree add --track -b <branch> <path> <remote>/<branch> | |
80 | ------------ | |
81 | + | |
8d7b558b ÆAB |
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 `<branch>` 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 `<branch>` is ambiguous but exists on the | |
e79e313c | 88 | `origin` remote. See also `checkout.defaultRemote` in |
8d7b558b ÆAB |
89 | linkgit:git-config[1]. |
90 | + | |
c4738aed | 91 | If `<commit-ish>` is omitted and neither `-b` nor `-B` nor `--detach` used, |
59970144 DS |
92 | then, as a convenience, the new worktree is associated with a branch (call |
93 | it `<branch>`) named after `$(basename <path>)`. If `<branch>` doesn't | |
94 | exist, a new branch based on `HEAD` is automatically created as if | |
95 | `-b <branch>` was given. If `<branch>` 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). | |
fc56361f | 98 | |
bb9c03b8 MR |
99 | list:: |
100 | ||
59970144 DS |
101 | List details of each worktree. The main worktree is listed first, |
102 | followed by each of the linked worktrees. The output details include | |
103 | whether the worktree is bare, the revision currently checked out, the | |
9b19a58f | 104 | branch currently checked out (or "detached HEAD" if none), "locked" if |
59970144 DS |
105 | the worktree is locked, "prunable" if the worktree can be pruned by the |
106 | `prune` command. | |
bb9c03b8 | 107 | |
58142c09 NTND |
108 | lock:: |
109 | ||
59970144 DS |
110 | If a worktree is on a portable device or network share which is not always |
111 | mounted, lock it to prevent its administrative files from being pruned | |
112 | automatically. This also prevents it from being moved or deleted. | |
113 | Optionally, specify a reason for the lock with `--reason`. | |
58142c09 | 114 | |
9f792bb4 NTND |
115 | move:: |
116 | ||
59970144 DS |
117 | Move a worktree to a new location. Note that the main worktree or linked |
118 | worktrees containing submodules cannot be moved with this command. (The | |
119 | `git worktree repair` command, however, can reestablish the connection | |
120 | with linked worktrees if you move the main worktree manually.) | |
9f792bb4 | 121 | |
7b722d90 NTND |
122 | prune:: |
123 | ||
59970144 | 124 | Prune worktree information in `$GIT_DIR/worktrees`. |
7b722d90 | 125 | |
cc73385c NTND |
126 | remove:: |
127 | ||
59970144 DS |
128 | Remove a worktree. Only clean worktrees (no untracked files and no |
129 | modification in tracked files) can be removed. Unclean worktrees or ones | |
130 | with submodules can be removed with `--force`. The main worktree cannot be | |
131 | removed. | |
cc73385c | 132 | |
b214ab5a | 133 | repair [<path>...]:: |
e8e1ff24 | 134 | |
59970144 DS |
135 | Repair worktree administrative files, if possible, if they have become |
136 | corrupted or outdated due to external factors. | |
bdd1f3e4 | 137 | + |
59970144 DS |
138 | For instance, if the main worktree (or bare repository) is moved, linked |
139 | worktrees will be unable to locate it. Running `repair` in the main | |
140 | worktree will reestablish the connection from linked worktrees back to the | |
141 | main worktree. | |
b214ab5a | 142 | + |
59970144 DS |
143 | Similarly, if the working tree for a linked worktree is moved without |
144 | using `git worktree move`, the main worktree (or bare repository) will be | |
145 | unable to locate it. Running `repair` within the recently-moved worktree | |
146 | will reestablish the connection. If multiple linked worktrees are moved, | |
147 | running `repair` from any worktree with each tree's new `<path>` as an | |
148 | argument, will reestablish the connection to all the specified paths. | |
cf76baea | 149 | + |
59970144 DS |
150 | If both the main worktree and linked worktrees have been moved manually, |
151 | then running `repair` in the main worktree and specifying the new `<path>` | |
152 | of each linked worktree will reestablish all connections in both | |
153 | directions. | |
e8e1ff24 | 154 | |
6d308627 NTND |
155 | unlock:: |
156 | ||
59970144 | 157 | Unlock a worktree, allowing it to be pruned, moved or deleted. |
6d308627 | 158 | |
df0b6cfb NTND |
159 | OPTIONS |
160 | ------- | |
161 | ||
f4325444 ES |
162 | -f:: |
163 | --force:: | |
6036be14 | 164 | By default, `add` refuses to create a new worktree when |
cc73385c | 165 | `<commit-ish>` is a branch name and is already checked out by |
6036be14 DS |
166 | another worktree, or if `<path>` is already assigned to some |
167 | worktree but is missing (for instance, if `<path>` was deleted | |
e19831c9 | 168 | manually). This option overrides these safeguards. To add a missing but |
6036be14 | 169 | locked worktree path, specify `--force` twice. |
e19831c9 | 170 | + |
6036be14 DS |
171 | `move` refuses to move a locked worktree unless `--force` is specified |
172 | twice. If the destination is already assigned to some other worktree but is | |
810382ed | 173 | missing (for instance, if `<new-path>` was deleted manually), then `--force` |
e79e313c | 174 | allows the move to proceed; use `--force` twice if the destination is locked. |
68a6b3a1 | 175 | + |
6036be14 DS |
176 | `remove` refuses to remove an unclean worktree unless `--force` is used. |
177 | To remove a locked worktree, specify `--force` twice. | |
f4325444 | 178 | |
cbdf60fa ES |
179 | -b <new-branch>:: |
180 | -B <new-branch>:: | |
181 | With `add`, create a new branch named `<new-branch>` starting at | |
6036be14 | 182 | `<commit-ish>`, and check out `<new-branch>` into the new worktree. |
e79e313c | 183 | If `<commit-ish>` is omitted, it defaults to `HEAD`. |
cbdf60fa ES |
184 | By default, `-b` refuses to create a new branch if it already |
185 | exists. `-B` overrides this safeguard, resetting `<new-branch>` to | |
c4738aed | 186 | `<commit-ish>`. |
cbdf60fa | 187 | |
c670aa47 | 188 | -d:: |
39ecb274 | 189 | --detach:: |
6036be14 | 190 | With `add`, detach `HEAD` in the new worktree. See "DETACHED HEAD" |
bc483285 | 191 | in linkgit:git-checkout[1]. |
39ecb274 | 192 | |
ef2a0ac9 | 193 | --[no-]checkout:: |
c4738aed | 194 | By default, `add` checks out `<commit-ish>`, however, `--no-checkout` can |
ef2a0ac9 RZ |
195 | be used to suppress checkout in order to make customizations, |
196 | such as configuring sparse-checkout. See "Sparse checkout" | |
197 | in linkgit:git-read-tree[1]. | |
198 | ||
71d6682d TG |
199 | --[no-]guess-remote:: |
200 | With `worktree add <path>`, without `<commit-ish>`, instead | |
e79e313c | 201 | of creating a new branch from `HEAD`, if there exists a tracking |
50fdf7b1 | 202 | branch in exactly one remote matching the basename of `<path>`, |
71d6682d TG |
203 | base the new branch on the remote-tracking branch, and mark |
204 | the remote-tracking branch as "upstream" from the new branch. | |
e92445a7 TG |
205 | + |
206 | This can also be set up as the default behaviour by using the | |
207 | `worktree.guessRemote` config option. | |
71d6682d | 208 | |
e284e892 TG |
209 | --[no-]track:: |
210 | When creating a new branch, if `<commit-ish>` is a branch, | |
211 | mark it as "upstream" from the new branch. This is the | |
212 | default if `<commit-ish>` is a remote-tracking branch. See | |
e79e313c | 213 | `--track` in linkgit:git-branch[1] for details. |
e284e892 | 214 | |
507e6e9e | 215 | --lock:: |
6036be14 | 216 | Keep the worktree locked after creation. This is the |
507e6e9e | 217 | equivalent of `git worktree lock` after `git worktree add`, |
ff1ce500 | 218 | but without a race condition. |
507e6e9e | 219 | |
df0b6cfb NTND |
220 | -n:: |
221 | --dry-run:: | |
4f09825e | 222 | With `prune`, do not remove anything; just report what it would |
df0b6cfb NTND |
223 | remove. |
224 | ||
bb9c03b8 MR |
225 | --porcelain:: |
226 | With `list`, output in an easy-to-parse format for scripts. | |
227 | This format will remain stable across Git versions and regardless of user | |
d97eb302 PW |
228 | configuration. It is recommended to combine this with `-z`. |
229 | See below for details. | |
230 | ||
231 | -z:: | |
232 | Terminate each line with a NUL rather than a newline when | |
233 | `--porcelain` is specified with `list`. This makes it possible | |
234 | to parse the output when a worktree path contains a newline | |
235 | character. | |
bb9c03b8 | 236 | |
371979c2 EP |
237 | -q:: |
238 | --quiet:: | |
e79e313c | 239 | With `add`, suppress feedback messages. |
371979c2 | 240 | |
df0b6cfb NTND |
241 | -v:: |
242 | --verbose:: | |
4f09825e | 243 | With `prune`, report all removals. |
076b444a RS |
244 | + |
245 | With `list`, output additional information about worktrees (see below). | |
df0b6cfb NTND |
246 | |
247 | --expire <time>:: | |
6036be14 | 248 | With `prune`, only expire unused worktrees older than `<time>`. |
9b19a58f | 249 | + |
6036be14 DS |
250 | With `list`, annotate missing worktrees as prunable if they are older than |
251 | `<time>`. | |
df0b6cfb | 252 | |
58142c09 | 253 | --reason <string>:: |
6036be14 DS |
254 | With `lock` or with `add --lock`, an explanation why the worktree |
255 | is locked. | |
58142c09 NTND |
256 | |
257 | <worktree>:: | |
6036be14 | 258 | Worktrees can be identified by path, either relative or absolute. |
080739ba | 259 | + |
6036be14 DS |
260 | If the last path components in the worktree's path is unique among |
261 | worktrees, it can be used to identify a worktree. For example if you only | |
262 | have two worktrees, at `/abc/def/ghi` and `/abc/def/ggg`, then `ghi` or | |
263 | `def/ghi` is enough to point to the former worktree. | |
58142c09 | 264 | |
8aff1a9c NTND |
265 | REFS |
266 | ---- | |
a777d4c7 DS |
267 | When using multiple worktrees, some refs are shared between all worktrees, |
268 | but others are specific to an individual worktree. One example is `HEAD`, | |
269 | which is different for each worktree. This section is about the sharing | |
270 | rules and how to access refs of one worktree from another. | |
271 | ||
272 | In general, all pseudo refs are per-worktree and all refs starting with | |
273 | `refs/` are shared. Pseudo refs are ones like `HEAD` which are directly | |
274 | under `$GIT_DIR` instead of inside `$GIT_DIR/refs`. There are exceptions, | |
275 | however: refs inside `refs/bisect` and `refs/worktree` are not shared. | |
276 | ||
277 | Refs that are per-worktree can still be accessed from another worktree via | |
278 | two special paths, `main-worktree` and `worktrees`. The former gives | |
279 | access to per-worktree refs of the main worktree, while the latter to all | |
280 | linked worktrees. | |
3a3b9d8c | 281 | |
e79e313c | 282 | For example, `main-worktree/HEAD` or `main-worktree/refs/bisect/good` |
a777d4c7 | 283 | resolve to the same value as the main worktree's `HEAD` and |
e79e313c ES |
284 | `refs/bisect/good` respectively. Similarly, `worktrees/foo/HEAD` or |
285 | `worktrees/bar/refs/bisect/bad` are the same as | |
286 | `$GIT_COMMON_DIR/worktrees/foo/HEAD` and | |
287 | `$GIT_COMMON_DIR/worktrees/bar/refs/bisect/bad`. | |
3a3b9d8c | 288 | |
e79e313c | 289 | To access refs, it's best not to look inside `$GIT_DIR` directly. Instead |
14f74d59 | 290 | use commands such as linkgit:git-rev-parse[1] or linkgit:git-update-ref[1] |
8aff1a9c NTND |
291 | which will handle refs correctly. |
292 | ||
58b284a2 NTND |
293 | CONFIGURATION FILE |
294 | ------------------ | |
7b215826 DS |
295 | By default, the repository `config` file is shared across all worktrees. |
296 | If the config variables `core.bare` or `core.worktree` are present in the | |
297 | common config file and `extensions.worktreeConfig` is disabled, then they | |
298 | will be applied to the main worktree only. | |
58b284a2 | 299 | |
7b215826 DS |
300 | In order to have worktree-specific configuration, you can turn on the |
301 | `worktreeConfig` extension, e.g.: | |
58b284a2 NTND |
302 | |
303 | ------------ | |
304 | $ git config extensions.worktreeConfig true | |
305 | ------------ | |
306 | ||
307 | In this mode, specific configuration stays in the path pointed by `git | |
308 | rev-parse --git-path config.worktree`. You can add or update | |
309 | configuration in this file with `git config --worktree`. Older Git | |
310 | versions will refuse to access repositories with this extension. | |
311 | ||
312 | Note that in this file, the exception for `core.bare` and `core.worktree` | |
ff1ce500 | 313 | is gone. If they exist in `$GIT_DIR/config`, you must move |
7b215826 DS |
314 | them to the `config.worktree` of the main worktree. You may also take this |
315 | opportunity to review and move other configuration that you do not want to | |
316 | share to all worktrees: | |
58b284a2 | 317 | |
5c11c0d5 DS |
318 | - `core.worktree` should never be shared. |
319 | ||
320 | - `core.bare` should not be shared if the value is `core.bare=true`. | |
58b284a2 | 321 | |
7b215826 DS |
322 | - `core.sparseCheckout` should not be shared, unless you are sure you |
323 | always use sparse checkout for all worktrees. | |
58b284a2 | 324 | |
5c11c0d5 DS |
325 | See the documentation of `extensions.worktreeConfig` in |
326 | linkgit:git-config[1] for more details. | |
327 | ||
af189b4c ES |
328 | DETAILS |
329 | ------- | |
f13a146c | 330 | Each linked worktree has a private sub-directory in the repository's |
e79e313c | 331 | `$GIT_DIR/worktrees` directory. The private sub-directory's name is usually |
f13a146c | 332 | the base name of the linked worktree's path, possibly appended with a |
af189b4c | 333 | number to make it unique. For example, when `$GIT_DIR=/path/main/.git` the |
4d5a3c58 | 334 | command `git worktree add /path/other/test-next next` creates the linked |
f13a146c | 335 | worktree in `/path/other/test-next` and also creates a |
af189b4c ES |
336 | `$GIT_DIR/worktrees/test-next` directory (or `$GIT_DIR/worktrees/test-next1` |
337 | if `test-next` is already taken). | |
338 | ||
f13a146c | 339 | Within a linked worktree, `$GIT_DIR` is set to point to this private |
af189b4c | 340 | directory (e.g. `/path/main/.git/worktrees/test-next` in the example) and |
f13a146c | 341 | `$GIT_COMMON_DIR` is set to point back to the main worktree's `$GIT_DIR` |
af189b4c | 342 | (e.g. `/path/main/.git`). These settings are made in a `.git` file located at |
f13a146c | 343 | the top directory of the linked worktree. |
af189b4c ES |
344 | |
345 | Path resolution via `git rev-parse --git-path` uses either | |
e79e313c | 346 | `$GIT_DIR` or `$GIT_COMMON_DIR` depending on the path. For example, in the |
f13a146c | 347 | linked worktree `git rev-parse --git-path HEAD` returns |
af189b4c ES |
348 | `/path/main/.git/worktrees/test-next/HEAD` (not |
349 | `/path/other/test-next/.git/HEAD` or `/path/main/.git/HEAD`) while `git | |
350 | rev-parse --git-path refs/heads/master` uses | |
e79e313c | 351 | `$GIT_COMMON_DIR` and returns `/path/main/.git/refs/heads/master`, |
f13a146c | 352 | since refs are shared across all worktrees, except `refs/bisect` and |
e79e313c | 353 | `refs/worktree`. |
af189b4c ES |
354 | |
355 | See linkgit:gitrepository-layout[5] for more information. The rule of | |
356 | thumb is do not make any assumption about whether a path belongs to | |
e79e313c ES |
357 | `$GIT_DIR` or `$GIT_COMMON_DIR` when you need to directly access something |
358 | inside `$GIT_DIR`. Use `git rev-parse --git-path` to get the final path. | |
af189b4c | 359 | |
f13a146c DS |
360 | If you manually move a linked worktree, you need to update the `gitdir` file |
361 | in the entry's directory. For example, if a linked worktree is moved | |
618244e1 NTND |
362 | to `/newpath/test-next` and its `.git` file points to |
363 | `/path/main/.git/worktrees/test-next`, then update | |
364 | `/path/main/.git/worktrees/test-next/gitdir` to reference `/newpath/test-next` | |
b214ab5a ES |
365 | instead. Better yet, run `git worktree repair` to reestablish the connection |
366 | automatically. | |
618244e1 | 367 | |
e79e313c | 368 | To prevent a `$GIT_DIR/worktrees` entry from being pruned (which |
a8ba5dd7 | 369 | can be useful in some situations, such as when the |
f13a146c | 370 | entry's worktree is stored on a portable device), use the |
58142c09 | 371 | `git worktree lock` command, which adds a file named |
e79e313c | 372 | `locked` to the entry's directory. The file contains the reason in |
f13a146c | 373 | plain text. For example, if a linked worktree's `.git` file points |
a8ba5dd7 ES |
374 | to `/path/main/.git/worktrees/test-next` then a file named |
375 | `/path/main/.git/worktrees/test-next/locked` will prevent the | |
376 | `test-next` entry from being pruned. See | |
377 | linkgit:gitrepository-layout[5] for details. | |
378 | ||
e79e313c | 379 | When `extensions.worktreeConfig` is enabled, the config file |
58b284a2 | 380 | `.git/worktrees/<id>/config.worktree` is read after `.git/config` is. |
a8ba5dd7 | 381 | |
bb9c03b8 MR |
382 | LIST OUTPUT FORMAT |
383 | ------------------ | |
e79e313c | 384 | The `worktree list` command has two output formats. The default format shows the |
bb9c03b8 MR |
385 | details on a single line with columns. For example: |
386 | ||
387 | ------------ | |
22d11a6e | 388 | $ git worktree list |
bb9c03b8 MR |
389 | /path/to/bare-source (bare) |
390 | /path/to/linked-worktree abcd1234 [master] | |
391 | /path/to/other-linked-worktree 1234abc (detached HEAD) | |
392 | ------------ | |
393 | ||
07d85380 | 394 | The command also shows annotations for each worktree, according to its state. |
9b19a58f RS |
395 | These annotations are: |
396 | ||
07d85380 DS |
397 | * `locked`, if the worktree is locked. |
398 | * `prunable`, if the worktree can be pruned via `git worktree prune`. | |
9b19a58f RS |
399 | |
400 | ------------ | |
401 | $ git worktree list | |
402 | /path/to/linked-worktree abcd1234 [master] | |
98c7656a | 403 | /path/to/locked-worktree acbd5678 (brancha) locked |
9b19a58f RS |
404 | /path/to/prunable-worktree 5678abc (detached HEAD) prunable |
405 | ------------ | |
406 | ||
076b444a RS |
407 | For these annotations, a reason might also be available and this can be |
408 | seen using the verbose mode. The annotation is then moved to the next line | |
409 | indented followed by the additional information. | |
410 | ||
411 | ------------ | |
412 | $ git worktree list --verbose | |
413 | /path/to/linked-worktree abcd1234 [master] | |
414 | /path/to/locked-worktree-no-reason abcd5678 (detached HEAD) locked | |
415 | /path/to/locked-worktree-with-reason 1234abcd (brancha) | |
07d85380 | 416 | locked: worktree path is mounted on a portable device |
076b444a RS |
417 | /path/to/prunable-worktree 5678abc1 (detached HEAD) |
418 | prunable: gitdir file points to non-existent location | |
419 | ------------ | |
420 | ||
421 | Note that the annotation is moved to the next line if the additional | |
422 | information is available, otherwise it stays on the same line as the | |
07d85380 | 423 | worktree itself. |
076b444a | 424 | |
bb9c03b8 MR |
425 | Porcelain Format |
426 | ~~~~~~~~~~~~~~~~ | |
d97eb302 PW |
427 | The porcelain format has a line per attribute. If `-z` is given then the lines |
428 | are terminated with NUL rather than a newline. Attributes are listed with a | |
e79e313c | 429 | label and value separated by a single space. Boolean attributes (like `bare` |
ff1ce500 | 430 | and `detached`) are listed as a label only, and are present only |
862c723d RS |
431 | if the value is true. Some attributes (like `locked`) can be listed as a label |
432 | only or with a value depending upon whether a reason is available. The first | |
07d85380 | 433 | attribute of a worktree is always `worktree`, an empty line indicates the |
862c723d | 434 | end of the record. For example: |
bb9c03b8 MR |
435 | |
436 | ------------ | |
22d11a6e | 437 | $ git worktree list --porcelain |
bb9c03b8 MR |
438 | worktree /path/to/bare-source |
439 | bare | |
440 | ||
441 | worktree /path/to/linked-worktree | |
442 | HEAD abcd1234abcd1234abcd1234abcd1234abcd1234 | |
443 | branch refs/heads/master | |
444 | ||
445 | worktree /path/to/other-linked-worktree | |
446 | HEAD 1234abc1234abc1234abc1234abc1234abc1234a | |
447 | detached | |
448 | ||
862c723d RS |
449 | worktree /path/to/linked-worktree-locked-no-reason |
450 | HEAD 5678abc5678abc5678abc5678abc5678abc5678c | |
451 | branch refs/heads/locked-no-reason | |
452 | locked | |
453 | ||
454 | worktree /path/to/linked-worktree-locked-with-reason | |
455 | HEAD 3456def3456def3456def3456def3456def3456b | |
456 | branch refs/heads/locked-with-reason | |
457 | locked reason why is locked | |
458 | ||
9b19a58f RS |
459 | worktree /path/to/linked-worktree-prunable |
460 | HEAD 1233def1234def1234def1234def1234def1234b | |
461 | detached | |
462 | prunable gitdir file points to non-existent location | |
463 | ||
862c723d RS |
464 | ------------ |
465 | ||
d97eb302 | 466 | Unless `-z` is used any "unusual" characters in the lock reason such as newlines |
862c723d RS |
467 | are escaped and the entire reason is quoted as explained for the |
468 | configuration variable `core.quotePath` (see linkgit:git-config[1]). | |
469 | For Example: | |
470 | ||
471 | ------------ | |
472 | $ git worktree list --porcelain | |
473 | ... | |
474 | locked "reason\nwhy is locked" | |
475 | ... | |
bb9c03b8 MR |
476 | ------------ |
477 | ||
96454597 ES |
478 | EXAMPLES |
479 | -------- | |
480 | You are in the middle of a refactoring session and your boss comes in and | |
481 | demands that you fix something immediately. You might typically use | |
482 | linkgit:git-stash[1] to store your changes away temporarily, however, your | |
bc483285 MH |
483 | working tree is in such a state of disarray (with new, moved, and removed |
484 | files, and other bits and pieces strewn around) that you don't want to risk | |
07d85380 | 485 | disturbing any of it. Instead, you create a temporary linked worktree to |
96454597 ES |
486 | make the emergency fix, remove it when done, and then resume your earlier |
487 | refactoring session. | |
488 | ||
489 | ------------ | |
cbdf60fa | 490 | $ git worktree add -b emergency-fix ../temp master |
96454597 ES |
491 | $ pushd ../temp |
492 | # ... hack hack hack ... | |
493 | $ git commit -a -m 'emergency fix for boss' | |
494 | $ popd | |
3f0b42bd | 495 | $ git worktree remove ../temp |
96454597 ES |
496 | ------------ |
497 | ||
6d3824cf ES |
498 | BUGS |
499 | ---- | |
18b22dbe JH |
500 | Multiple checkout in general is still experimental, and the support |
501 | for submodules is incomplete. It is NOT recommended to make multiple | |
502 | checkouts of a superproject. | |
6d3824cf | 503 | |
df0b6cfb NTND |
504 | GIT |
505 | --- | |
506 | Part of the linkgit:git[1] suite |