@@ -25,8 +25,9 @@ Manage multiple working trees attached to the same repository.
25
25
A git repository can support multiple working trees, allowing you to check
26
26
out more than one branch at a time. With `git worktree add` a new working
27
27
tree is associated with the repository. This new working tree is called a
28
- "linked working tree" as opposed to the "main working tree" prepared by "git
29
- init" or "git clone". A repository has one main working tree (if it's not a
28
+ "linked working tree" as opposed to the "main working tree" prepared by
29
+ linkgit:git-init[1] or linkgit:git-clone[1].
30
+ A repository has one main working tree (if it's not a
30
31
bare repository) and zero or more linked working trees. When you are done
31
32
with a linked working tree, remove it with `git worktree remove`.
32
33
@@ -48,10 +49,10 @@ add <path> [<commit-ish>]::
48
49
49
50
Create `<path>` and checkout `<commit-ish>` into it. The new working directory
50
51
is linked to the current repository, sharing everything except working
51
- directory specific files such as HEAD, index, etc. `-` may also be
52
- specified as `<commit-ish>`; it is synonymous with `@{-1}`.
52
+ directory specific files such as ` HEAD`, ` index` , etc. As a convenience,
53
+ `<commit-ish>` may be a bare "`-`", which is synonymous with `@{-1}`.
53
54
+
54
- If <commit-ish> is a branch name (call it `<branch>`) and is not found,
55
+ If ` <commit-ish>` is a branch name (call it `<branch>`) and is not found,
55
56
and neither `-b` nor `-B` nor `--detach` are used, but there does
56
57
exist a tracking branch in exactly one remote (call it `<remote>`)
57
58
with a matching name, treat as equivalent to:
@@ -66,24 +67,24 @@ one for the purposes of disambiguation, even if the `<branch>` isn't
66
67
unique across all remotes. Set it to
67
68
e.g. `checkout.defaultRemote=origin` to always checkout remote
68
69
branches from there if `<branch>` is ambiguous but exists on the
69
- ' origin' remote. See also `checkout.defaultRemote` in
70
+ ` origin` remote. See also `checkout.defaultRemote` in
70
71
linkgit:git-config[1].
71
72
+
72
73
If `<commit-ish>` is omitted and neither `-b` nor `-B` nor `--detach` used,
73
- then, as a convenience, the new worktree is associated with a branch
74
+ then, as a convenience, the new working tree is associated with a branch
74
75
(call it `<branch>`) named after `$(basename <path>)`. If `<branch>`
75
- doesn't exist, a new branch based on HEAD is automatically created as
76
+ doesn't exist, a new branch based on ` HEAD` is automatically created as
76
77
if `-b <branch>` was given. If `<branch>` does exist, it will be
77
- checked out in the new worktree , if it's not checked out anywhere
78
- else, otherwise the command will refuse to create the worktree (unless
78
+ checked out in the new working tree , if it's not checked out anywhere
79
+ else, otherwise the command will refuse to create the working tree (unless
79
80
`--force` is used).
80
81
81
82
list::
82
83
83
- List details of each worktree . The main worktree is listed first, followed by
84
- each of the linked worktrees . The output details include if the worktree is
85
- bare, the revision currently checked out, and the branch currently checked out
86
- (or ' detached HEAD' if none).
84
+ List details of each working tree . The main working tree is listed first,
85
+ followed by each of the linked working trees . The output details include
86
+ whether the working tree is bare, the revision currently checked out, and the
87
+ branch currently checked out (or " detached HEAD" if none).
87
88
88
89
lock::
89
90
@@ -100,7 +101,7 @@ or linked working trees containing submodules cannot be moved.
100
101
101
102
prune::
102
103
103
- Prune working tree information in $GIT_DIR/worktrees.
104
+ Prune working tree information in ` $GIT_DIR/worktrees` .
104
105
105
106
remove::
106
107
@@ -128,7 +129,7 @@ OPTIONS
128
129
`move` refuses to move a locked working tree unless `--force` is specified
129
130
twice. If the destination is already assigned to some other working tree but is
130
131
missing (for instance, if `<new-path>` was deleted manually), then `--force`
131
- allows the move to proceed; use --force twice if the destination is locked.
132
+ allows the move to proceed; use ` --force` twice if the destination is locked.
132
133
+
133
134
`remove` refuses to remove an unclean working tree unless `--force` is used.
134
135
To remove a locked working tree, specify `--force` twice.
@@ -137,13 +138,13 @@ To remove a locked working tree, specify `--force` twice.
137
138
-B <new-branch>::
138
139
With `add`, create a new branch named `<new-branch>` starting at
139
140
`<commit-ish>`, and check out `<new-branch>` into the new working tree.
140
- If `<commit-ish>` is omitted, it defaults to HEAD.
141
+ If `<commit-ish>` is omitted, it defaults to ` HEAD` .
141
142
By default, `-b` refuses to create a new branch if it already
142
143
exists. `-B` overrides this safeguard, resetting `<new-branch>` to
143
144
`<commit-ish>`.
144
145
145
146
--detach::
146
- With `add`, detach HEAD in the new working tree. See "DETACHED HEAD"
147
+ With `add`, detach ` HEAD` in the new working tree. See "DETACHED HEAD"
147
148
in linkgit:git-checkout[1].
148
149
149
150
--[no-]checkout::
@@ -154,7 +155,7 @@ To remove a locked working tree, specify `--force` twice.
154
155
155
156
--[no-]guess-remote::
156
157
With `worktree add <path>`, without `<commit-ish>`, instead
157
- of creating a new branch from HEAD, if there exists a tracking
158
+ of creating a new branch from ` HEAD` , if there exists a tracking
158
159
branch in exactly one remote matching the basename of `<path>`,
159
160
base the new branch on the remote-tracking branch, and mark
160
161
the remote-tracking branch as "upstream" from the new branch.
@@ -166,12 +167,12 @@ This can also be set up as the default behaviour by using the
166
167
When creating a new branch, if `<commit-ish>` is a branch,
167
168
mark it as "upstream" from the new branch. This is the
168
169
default if `<commit-ish>` is a remote-tracking branch. See
169
- " --track" in linkgit:git-branch[1] for details.
170
+ ` --track` in linkgit:git-branch[1] for details.
170
171
171
172
--lock::
172
173
Keep the working tree locked after creation. This is the
173
174
equivalent of `git worktree lock` after `git worktree add`,
174
- but without race condition.
175
+ but without a race condition.
175
176
176
177
-n::
177
178
--dry-run::
@@ -185,14 +186,14 @@ This can also be set up as the default behaviour by using the
185
186
186
187
-q::
187
188
--quiet::
188
- With ' add' , suppress feedback messages.
189
+ With ` add` , suppress feedback messages.
189
190
190
191
-v::
191
192
--verbose::
192
193
With `prune`, report all removals.
193
194
194
195
--expire <time>::
195
- With `prune`, only expire unused working trees older than <time>.
196
+ With `prune`, only expire unused working trees older than ` <time>` .
196
197
197
198
--reason <string>::
198
199
With `lock`, an explanation why the working tree is locked.
@@ -202,48 +203,48 @@ This can also be set up as the default behaviour by using the
202
203
absolute.
203
204
+
204
205
If the last path components in the working tree's path is unique among
205
- working trees, it can be used to identify worktrees . For example if
206
- you only have two working trees, at " /abc/def/ghi" and " /abc/def/ggg" ,
207
- then " ghi" or " def/ghi" is enough to point to the former working tree.
206
+ working trees, it can be used to identify a working tree . For example if
207
+ you only have two working trees, at ` /abc/def/ghi` and ` /abc/def/ggg` ,
208
+ then ` ghi` or ` def/ghi` is enough to point to the former working tree.
208
209
209
210
REFS
210
211
----
211
212
In multiple working trees, some refs may be shared between all working
212
- trees, some refs are local. One example is HEAD is different for all
213
- working trees . This section is about the sharing rules and how to access
213
+ trees and some refs are local. One example is ` HEAD` which is different for each
214
+ working tree . This section is about the sharing rules and how to access
214
215
refs of one working tree from another.
215
216
216
217
In general, all pseudo refs are per working tree and all refs starting
217
- with " refs/" are shared. Pseudo refs are ones like HEAD which are
218
- directly under GIT_DIR instead of inside GIT_DIR/refs. There is one
219
- exception to this : refs inside refs/bisect and refs/worktree is not
218
+ with ` refs/` are shared. Pseudo refs are ones like ` HEAD` which are
219
+ directly under `$ GIT_DIR` instead of inside `$ GIT_DIR/refs` . There are
220
+ exceptions, however : refs inside ` refs/bisect` and ` refs/worktree` are not
220
221
shared.
221
222
222
223
Refs that are per working tree can still be accessed from another
223
- working tree via two special paths, main-worktree and worktrees. The
224
- former gives access to per-worktree refs of the main working tree,
224
+ working tree via two special paths, ` main-worktree` and ` worktrees` . The
225
+ former gives access to per-working tree refs of the main working tree,
225
226
while the latter to all linked working trees.
226
227
227
- For example, main-worktree/HEAD or main-worktree/refs/bisect/good
228
- resolve to the same value as the main working tree's HEAD and
229
- refs/bisect/good respectively. Similarly, worktrees/foo/HEAD or
230
- worktrees/bar/refs/bisect/bad are the same as
231
- GIT_COMMON_DIR/worktrees/foo/HEAD and
232
- GIT_COMMON_DIR/worktrees/bar/refs/bisect/bad.
228
+ For example, ` main-worktree/HEAD` or ` main-worktree/refs/bisect/good`
229
+ resolve to the same value as the main working tree's ` HEAD` and
230
+ ` refs/bisect/good` respectively. Similarly, ` worktrees/foo/HEAD` or
231
+ ` worktrees/bar/refs/bisect/bad` are the same as
232
+ `$ GIT_COMMON_DIR/worktrees/foo/HEAD` and
233
+ `$ GIT_COMMON_DIR/worktrees/bar/refs/bisect/bad` .
233
234
234
- To access refs, it's best not to look inside GIT_DIR directly. Instead
235
+ To access refs, it's best not to look inside `$ GIT_DIR` directly. Instead
235
236
use commands such as linkgit:git-rev-parse[1] or linkgit:git-update-ref[1]
236
237
which will handle refs correctly.
237
238
238
239
CONFIGURATION FILE
239
240
------------------
240
- By default, the repository " config" file is shared across all working
241
+ By default, the repository ` config` file is shared across all working
241
242
trees. If the config variables `core.bare` or `core.worktree` are
242
243
already present in the config file, they will be applied to the main
243
244
working trees only.
244
245
245
246
In order to have configuration specific to working trees, you can turn
246
- on " worktreeConfig" extension, e.g.:
247
+ on the ` worktreeConfig` extension, e.g.:
247
248
248
249
------------
249
250
$ git config extensions.worktreeConfig true
@@ -255,7 +256,7 @@ configuration in this file with `git config --worktree`. Older Git
255
256
versions will refuse to access repositories with this extension.
256
257
257
258
Note that in this file, the exception for `core.bare` and `core.worktree`
258
- is gone. If you have them in $GIT_DIR/config before , you must move
259
+ is gone. If they exist in ` $GIT_DIR/config` , you must move
259
260
them to the `config.worktree` of the main working tree. You may also
260
261
take this opportunity to review and move other configuration that you
261
262
do not want to share to all working trees:
@@ -268,59 +269,59 @@ do not want to share to all working trees:
268
269
DETAILS
269
270
-------
270
271
Each linked working tree has a private sub-directory in the repository's
271
- $GIT_DIR/worktrees directory. The private sub-directory's name is usually
272
+ ` $GIT_DIR/worktrees` directory. The private sub-directory's name is usually
272
273
the base name of the linked working tree's path, possibly appended with a
273
274
number to make it unique. For example, when `$GIT_DIR=/path/main/.git` the
274
275
command `git worktree add /path/other/test-next next` creates the linked
275
276
working tree in `/path/other/test-next` and also creates a
276
277
`$GIT_DIR/worktrees/test-next` directory (or `$GIT_DIR/worktrees/test-next1`
277
278
if `test-next` is already taken).
278
279
279
- Within a linked working tree, $GIT_DIR is set to point to this private
280
+ Within a linked working tree, ` $GIT_DIR` is set to point to this private
280
281
directory (e.g. `/path/main/.git/worktrees/test-next` in the example) and
281
- $GIT_COMMON_DIR is set to point back to the main working tree's $GIT_DIR
282
+ ` $GIT_COMMON_DIR` is set to point back to the main working tree's ` $GIT_DIR`
282
283
(e.g. `/path/main/.git`). These settings are made in a `.git` file located at
283
284
the top directory of the linked working tree.
284
285
285
286
Path resolution via `git rev-parse --git-path` uses either
286
- $GIT_DIR or $GIT_COMMON_DIR depending on the path. For example, in the
287
+ ` $GIT_DIR` or ` $GIT_COMMON_DIR` depending on the path. For example, in the
287
288
linked working tree `git rev-parse --git-path HEAD` returns
288
289
`/path/main/.git/worktrees/test-next/HEAD` (not
289
290
`/path/other/test-next/.git/HEAD` or `/path/main/.git/HEAD`) while `git
290
291
rev-parse --git-path refs/heads/master` uses
291
- $GIT_COMMON_DIR and returns `/path/main/.git/refs/heads/master`,
292
- since refs are shared across all working trees, except refs/bisect and
293
- refs/worktree.
292
+ ` $GIT_COMMON_DIR` and returns `/path/main/.git/refs/heads/master`,
293
+ since refs are shared across all working trees, except ` refs/bisect` and
294
+ ` refs/worktree` .
294
295
295
296
See linkgit:gitrepository-layout[5] for more information. The rule of
296
297
thumb is do not make any assumption about whether a path belongs to
297
- $GIT_DIR or $GIT_COMMON_DIR when you need to directly access something
298
- inside $GIT_DIR. Use `git rev-parse --git-path` to get the final path.
298
+ ` $GIT_DIR` or ` $GIT_COMMON_DIR` when you need to directly access something
299
+ inside ` $GIT_DIR` . Use `git rev-parse --git-path` to get the final path.
299
300
300
- If you manually move a linked working tree, you need to update the ' gitdir' file
301
+ If you manually move a linked working tree, you need to update the ` gitdir` file
301
302
in the entry's directory. For example, if a linked working tree is moved
302
303
to `/newpath/test-next` and its `.git` file points to
303
304
`/path/main/.git/worktrees/test-next`, then update
304
305
`/path/main/.git/worktrees/test-next/gitdir` to reference `/newpath/test-next`
305
306
instead.
306
307
307
- To prevent a $GIT_DIR/worktrees entry from being pruned (which
308
+ To prevent a ` $GIT_DIR/worktrees` entry from being pruned (which
308
309
can be useful in some situations, such as when the
309
310
entry's working tree is stored on a portable device), use the
310
311
`git worktree lock` command, which adds a file named
311
- ' locked' to the entry's directory. The file contains the reason in
312
+ ` locked` to the entry's directory. The file contains the reason in
312
313
plain text. For example, if a linked working tree's `.git` file points
313
314
to `/path/main/.git/worktrees/test-next` then a file named
314
315
`/path/main/.git/worktrees/test-next/locked` will prevent the
315
316
`test-next` entry from being pruned. See
316
317
linkgit:gitrepository-layout[5] for details.
317
318
318
- When extensions.worktreeConfig is enabled, the config file
319
+ When ` extensions.worktreeConfig` is enabled, the config file
319
320
`.git/worktrees/<id>/config.worktree` is read after `.git/config` is.
320
321
321
322
LIST OUTPUT FORMAT
322
323
------------------
323
- The worktree list command has two output formats. The default format shows the
324
+ The ` worktree list` command has two output formats. The default format shows the
324
325
details on a single line with columns. For example:
325
326
326
327
------------
@@ -333,10 +334,10 @@ $ git worktree list
333
334
Porcelain Format
334
335
~~~~~~~~~~~~~~~~
335
336
The porcelain format has a line per attribute. Attributes are listed with a
336
- label and value separated by a single space. Boolean attributes (like ' bare'
337
- and ' detached' ) are listed as a label only, and are only present if and only
338
- if the value is true. The first attribute of a worktree is always `worktree`,
339
- an empty line indicates the end of the record. For example:
337
+ label and value separated by a single space. Boolean attributes (like ` bare`
338
+ and ` detached` ) are listed as a label only, and are present only
339
+ if the value is true. The first attribute of a working tree is always
340
+ `worktree`, an empty line indicates the end of the record. For example:
340
341
341
342
------------
342
343
$ git worktree list --porcelain
0 commit comments