]> git.ipfire.org Git - thirdparty/git.git/blob - Documentation/git-worktree.txt
2954dc6dc2c6d826ddc0f959e16453eac47f101b
[thirdparty/git.git] / Documentation / git-worktree.txt
1 git-worktree(1)
2 ===============
3
4 NAME
5 ----
6 git-worktree - Manage multiple worktrees
7
8
9 SYNOPSIS
10 --------
11 [verse]
12 'git worktree prune' [-n] [-v] [--expire <expire>]
13
14 DESCRIPTION
15 -----------
16
17 Manage multiple worktrees attached to the same repository. These are
18 created by the command `git checkout --to`.
19
20 A git repository can support multiple working trees, allowing you to check
21 out more than one branch at a time. With `git checkout --to` a new working
22 tree is associated with the repository. This new working tree is called a
23 "linked working tree" as opposed to the "main working tree" prepared by "git
24 init" or "git clone". A repository has one main working tree (if it's not a
25 bare repository) and zero or more linked working trees.
26
27 When you are done with a linked working tree you can simply delete it.
28 The working tree's administrative files in the repository (see
29 "DETAILS" below) will eventually be removed automatically (see
30 `gc.pruneworktreesexpire` in linkgit::git-config[1]), or you can run
31 `git worktree prune` in the main or any linked working tree to
32 clean up any stale administrative files.
33
34 If you move a linked working directory to another file system, or
35 within a file system that does not support hard links, you need to run
36 at least one git command inside the linked working directory
37 (e.g. `git status`) in order to update its administrative files in the
38 repository so that they do not get automatically pruned.
39
40 To prevent a $GIT_DIR/worktrees entry from from being pruned (which
41 can be useful in some situations, such as when the
42 entry's working tree is stored on a portable device), add a file named
43 'locked' to the entry's directory. The file contains the reason in
44 plain text. For example, if a linked working tree's `.git` file points
45 to `/path/main/.git/worktrees/test-next` then a file named
46 `/path/main/.git/worktrees/test-next/locked` will prevent the
47 `test-next` entry from being pruned. See
48 linkgit:gitrepository-layout[5] for details.
49
50 COMMANDS
51 --------
52 prune::
53
54 Prune working tree information in $GIT_DIR/worktrees.
55
56 OPTIONS
57 -------
58
59 -n::
60 --dry-run::
61 With `prune`, do not remove anything; just report what it would
62 remove.
63
64 -v::
65 --verbose::
66 With `prune`, report all removals.
67
68 --expire <time>::
69 With `prune`, only expire unused worktrees older than <time>.
70
71 DETAILS
72 -------
73 Each linked working tree has a private sub-directory in the repository's
74 $GIT_DIR/worktrees directory. The private sub-directory's name is usually
75 the base name of the linked working tree's path, possibly appended with a
76 number to make it unique. For example, when `$GIT_DIR=/path/main/.git` the
77 command `git checkout --to /path/other/test-next next` creates the linked
78 working tree in `/path/other/test-next` and also creates a
79 `$GIT_DIR/worktrees/test-next` directory (or `$GIT_DIR/worktrees/test-next1`
80 if `test-next` is already taken).
81
82 Within a linked working tree, $GIT_DIR is set to point to this private
83 directory (e.g. `/path/main/.git/worktrees/test-next` in the example) and
84 $GIT_COMMON_DIR is set to point back to the main working tree's $GIT_DIR
85 (e.g. `/path/main/.git`). These settings are made in a `.git` file located at
86 the top directory of the linked working tree.
87
88 Path resolution via `git rev-parse --git-path` uses either
89 $GIT_DIR or $GIT_COMMON_DIR depending on the path. For example, in the
90 linked working tree `git rev-parse --git-path HEAD` returns
91 `/path/main/.git/worktrees/test-next/HEAD` (not
92 `/path/other/test-next/.git/HEAD` or `/path/main/.git/HEAD`) while `git
93 rev-parse --git-path refs/heads/master` uses
94 $GIT_COMMON_DIR and returns `/path/main/.git/refs/heads/master`,
95 since refs are shared across all working trees.
96
97 See linkgit:gitrepository-layout[5] for more information. The rule of
98 thumb is do not make any assumption about whether a path belongs to
99 $GIT_DIR or $GIT_COMMON_DIR when you need to directly access something
100 inside $GIT_DIR. Use `git rev-parse --git-path` to get the final path.
101
102 BUGS
103 ----
104 Multiple checkout support for submodules is incomplete. It is NOT
105 recommended to make multiple checkouts of a superproject.
106
107 git-worktree could provide more automation for tasks currently
108 performed manually or via other commands, such as:
109
110 - `add` to create a new linked worktree
111 - `remove` to remove a linked worktree and its administrative files (and
112 warn if the worktree is dirty)
113 - `mv` to move or rename a worktree and update its administrative files
114 - `list` to list linked worktrees
115 - `lock` to prevent automatic pruning of administrative files (for instance,
116 for a worktree on a portable device)
117
118 SEE ALSO
119 --------
120
121 linkgit:git-checkout[1]
122
123 GIT
124 ---
125 Part of the linkgit:git[1] suite