@@ -229,8 +229,8 @@ section of linkgit:git-add[1] to learn how to operate the `--patch` mode.
229
229
Check out a branch in a separate working directory at
230
230
`<path>`. A new working directory is linked to the current
231
231
repository, sharing everything except working directory
232
- specific files such as HEAD, index... See "MULTIPLE WORKING
233
- TREES" section for more information .
232
+ specific files such as HEAD, index, etc. See
233
+ linkgit:git-worktree[1] for a description of linked worktrees .
234
234
235
235
--ignore-other-worktrees::
236
236
`git checkout` refuses when the wanted ref is already checked
@@ -401,71 +401,6 @@ $ git reflog -2 HEAD # or
401
401
$ git log -g -2 HEAD
402
402
------------
403
403
404
- MULTIPLE WORKING TREES
405
- ----------------------
406
-
407
- A git repository can support multiple working trees, allowing you to check
408
- out more than one branch at a time. With `git checkout --to` a new working
409
- tree is associated with the repository. This new working tree is called a
410
- "linked working tree" as opposed to the "main working tree" prepared by "git
411
- init" or "git clone". A repository has one main working tree (if it's not a
412
- bare repository) and zero or more linked working trees.
413
-
414
- Each linked working tree has a private sub-directory in the repository's
415
- $GIT_DIR/worktrees directory. The private sub-directory's name is usually
416
- the base name of the linked working tree's path, possibly appended with a
417
- number to make it unique. For example, when `$GIT_DIR=/path/main/.git` the
418
- command `git checkout --to /path/other/test-next next` creates the linked
419
- working tree in `/path/other/test-next` and also creates a
420
- `$GIT_DIR/worktrees/test-next` directory (or `$GIT_DIR/worktrees/test-next1`
421
- if `test-next` is already taken).
422
-
423
- Within a linked working tree, $GIT_DIR is set to point to this private
424
- directory (e.g. `/path/main/.git/worktrees/test-next` in the example) and
425
- $GIT_COMMON_DIR is set to point back to the main working tree's $GIT_DIR
426
- (e.g. `/path/main/.git`). These settings are made in a `.git` file located at
427
- the top directory of the linked working tree.
428
-
429
- Path resolution via `git rev-parse --git-path` uses either
430
- $GIT_DIR or $GIT_COMMON_DIR depending on the path. For example, in the
431
- linked working tree `git rev-parse --git-path HEAD` returns
432
- `/path/main/.git/worktrees/test-next/HEAD` (not
433
- `/path/other/test-next/.git/HEAD` or `/path/main/.git/HEAD`) while `git
434
- rev-parse --git-path refs/heads/master` uses
435
- $GIT_COMMON_DIR and returns `/path/main/.git/refs/heads/master`,
436
- since refs are shared across all working trees.
437
-
438
- See linkgit:gitrepository-layout[5] for more information. The rule of
439
- thumb is do not make any assumption about whether a path belongs to
440
- $GIT_DIR or $GIT_COMMON_DIR when you need to directly access something
441
- inside $GIT_DIR. Use `git rev-parse --git-path` to get the final path.
442
-
443
- When you are done with a linked working tree you can simply delete it.
444
- The working tree's entry in the repository's $GIT_DIR/worktrees
445
- directory will eventually be removed automatically (see
446
- `gc.pruneworktreesexpire` in linkgit::git-config[1]), or you can run
447
- `git worktree prune` in the main or any linked working tree to
448
- clean up any stale entries in $GIT_DIR/worktrees.
449
-
450
- If you move a linked working directory to another file system, or
451
- within a file system that does not support hard links, you need to run
452
- at least one git command inside the linked working directory
453
- (e.g. `git status`) in order to update its entry in $GIT_DIR/worktrees
454
- so that it does not get automatically removed.
455
-
456
- To prevent a $GIT_DIR/worktrees entry from from being pruned (which
457
- can be useful in some situations, such as when the
458
- entry's working tree is stored on a portable device), add a file named
459
- 'locked' to the entry's directory. The file contains the reason in
460
- plain text. For example, if a linked working tree's `.git` file points
461
- to `/path/main/.git/worktrees/test-next` then a file named
462
- `/path/main/.git/worktrees/test-next/locked` will prevent the
463
- `test-next` entry from being pruned. See
464
- linkgit:gitrepository-layout[5] for details.
465
-
466
- Multiple checkout support for submodules is incomplete. It is NOT
467
- recommended to make multiple checkouts of a superproject.
468
-
469
404
EXAMPLES
470
405
--------
471
406
0 commit comments