Nguyễn Thái Ngọc Duy | df0b6cf | 2015-06-29 19:51:18 +0700 | [diff] [blame] | 1 | git-worktree(1) |
| 2 | =============== |
| 3 | |
| 4 | NAME |
| 5 | ---- |
Michael Haggerty | bc48328 | 2015-07-20 01:29:18 -0400 | [diff] [blame] | 6 | git-worktree - Manage multiple working trees |
Nguyễn Thái Ngọc Duy | df0b6cf | 2015-06-29 19:51:18 +0700 | [diff] [blame] | 7 | |
| 8 | |
| 9 | SYNOPSIS |
| 10 | -------- |
| 11 | [verse] |
Stephen Manz | 0db4961 | 2021-07-15 02:32:30 +0000 | [diff] [blame] | 12 | 'git worktree add' [-f] [--detach] [--checkout] [--lock [--reason <string>]] [-b <new-branch>] <path> [<commit-ish>] |
Phillip Wood | d97eb30 | 2022-03-31 16:21:28 +0000 | [diff] [blame] | 13 | 'git worktree list' [-v | --porcelain [-z]] |
Nguyễn Thái Ngọc Duy | 58142c0 | 2016-06-13 19:18:24 +0700 | [diff] [blame] | 14 | 'git worktree lock' [--reason <string>] <worktree> |
Nguyễn Thái Ngọc Duy | 9f792bb | 2018-02-12 16:49:36 +0700 | [diff] [blame] | 15 | 'git worktree move' <worktree> <new-path> |
Nguyễn Thái Ngọc Duy | 7b722d9 | 2016-05-22 16:33:53 +0700 | [diff] [blame] | 16 | 'git worktree prune' [-n] [-v] [--expire <expire>] |
Stefan Beller | d228eea | 2018-04-17 11:19:39 -0700 | [diff] [blame] | 17 | 'git worktree remove' [-f] <worktree> |
Eric Sunshine | b214ab5 | 2020-08-31 02:57:58 -0400 | [diff] [blame] | 18 | 'git worktree repair' [<path>...] |
Nguyễn Thái Ngọc Duy | 6d30862 | 2016-06-13 19:18:25 +0700 | [diff] [blame] | 19 | 'git worktree unlock' <worktree> |
Nguyễn Thái Ngọc Duy | df0b6cf | 2015-06-29 19:51:18 +0700 | [diff] [blame] | 20 | |
| 21 | DESCRIPTION |
| 22 | ----------- |
| 23 | |
Michael Haggerty | bc48328 | 2015-07-20 01:29:18 -0400 | [diff] [blame] | 24 | Manage multiple working trees attached to the same repository. |
Nguyễn Thái Ngọc Duy | df0b6cf | 2015-06-29 19:51:18 +0700 | [diff] [blame] | 25 | |
Eric Sunshine | 93a3649 | 2015-07-06 13:30:40 -0400 | [diff] [blame] | 26 | A git repository can support multiple working trees, allowing you to check |
Eric Sunshine | 4d5a3c5 | 2015-07-16 18:09:43 -0400 | [diff] [blame] | 27 | out more than one branch at a time. With `git worktree add` a new working |
Derrick Stolee | c57bf8c | 2022-02-23 14:29:13 +0000 | [diff] [blame] | 28 | tree is associated with the repository, along with additional metadata |
| 29 | that differentiates that working tree from others in the same repository. |
| 30 | The working tree, along with this metadata, is called a "worktree". |
| 31 | |
| 32 | This new worktree is called a "linked worktree" as opposed to the "main |
| 33 | worktree" prepared by linkgit:git-init[1] or linkgit:git-clone[1]. |
| 34 | A repository has one main worktree (if it's not a bare repository) and |
| 35 | zero or more linked worktrees. When you are done with a linked worktree, |
| 36 | remove it with `git worktree remove`. |
Eric Sunshine | 93a3649 | 2015-07-06 13:30:40 -0400 | [diff] [blame] | 37 | |
Eric Sunshine | dccadad | 2020-09-06 20:02:22 -0400 | [diff] [blame] | 38 | In its simplest form, `git worktree add <path>` automatically creates a |
| 39 | new branch whose name is the final component of `<path>`, which is |
| 40 | convenient if you plan to work on a new topic. For instance, `git |
| 41 | worktree add ../hotfix` creates new branch `hotfix` and checks it out at |
Derrick Stolee | c57bf8c | 2022-02-23 14:29:13 +0000 | [diff] [blame] | 42 | path `../hotfix`. To instead work on an existing branch in a new worktree, |
| 43 | use `git worktree add <path> <branch>`. On the other hand, if you just |
| 44 | plan to make some experimental changes or do testing without disturbing |
| 45 | existing development, it is often convenient to create a 'throwaway' |
| 46 | worktree not associated with any branch. For instance, |
| 47 | `git worktree add -d <path>` creates a new worktree with a detached `HEAD` |
| 48 | at the same commit as the current branch. |
Eric Sunshine | dccadad | 2020-09-06 20:02:22 -0400 | [diff] [blame] | 49 | |
Eric Sunshine | 3f0b42b | 2018-04-09 03:33:59 -0400 | [diff] [blame] | 50 | If a working tree is deleted without using `git worktree remove`, then |
| 51 | its associated administrative files, which reside in the repository |
| 52 | (see "DETAILS" below), will eventually be removed automatically (see |
Eric Sunshine | 5f5f553 | 2015-07-24 00:00:52 -0400 | [diff] [blame] | 53 | `gc.worktreePruneExpire` in linkgit:git-config[1]), or you can run |
Derrick Stolee | c57bf8c | 2022-02-23 14:29:13 +0000 | [diff] [blame] | 54 | `git worktree prune` in the main or any linked worktree to clean up any |
| 55 | stale administrative files. |
Eric Sunshine | 93a3649 | 2015-07-06 13:30:40 -0400 | [diff] [blame] | 56 | |
Derrick Stolee | c57bf8c | 2022-02-23 14:29:13 +0000 | [diff] [blame] | 57 | If the working tree for a linked worktree is stored on a portable device |
| 58 | or network share which is not always mounted, you can prevent its |
| 59 | administrative files from being pruned by issuing the `git worktree lock` |
| 60 | command, optionally specifying `--reason` to explain why the worktree is |
| 61 | locked. |
Eric Sunshine | 93a3649 | 2015-07-06 13:30:40 -0400 | [diff] [blame] | 62 | |
Nguyễn Thái Ngọc Duy | df0b6cf | 2015-06-29 19:51:18 +0700 | [diff] [blame] | 63 | COMMANDS |
| 64 | -------- |
Thomas Gummerer | c4738ae | 2017-11-26 19:43:52 +0000 | [diff] [blame] | 65 | add <path> [<commit-ish>]:: |
Eric Sunshine | fc56361 | 2015-07-06 13:30:50 -0400 | [diff] [blame] | 66 | |
Derrick Stolee | c57bf8c | 2022-02-23 14:29:13 +0000 | [diff] [blame] | 67 | Create a worktree at `<path>` and checkout `<commit-ish>` into it. The new worktree |
| 68 | is linked to the current repository, sharing everything except per-worktree |
| 69 | files such as `HEAD`, `index`, etc. As a convenience, `<commit-ish>` may |
| 70 | be a bare "`-`", which is synonymous with `@{-1}`. |
Eric Sunshine | 1eb07d8 | 2015-07-06 13:30:59 -0400 | [diff] [blame] | 71 | + |
Eric Sunshine | e79e313 | 2020-08-03 20:55:31 -0400 | [diff] [blame] | 72 | If `<commit-ish>` is a branch name (call it `<branch>`) and is not found, |
Thomas Gummerer | 4e85333 | 2017-11-26 19:43:54 +0000 | [diff] [blame] | 73 | and neither `-b` nor `-B` nor `--detach` are used, but there does |
| 74 | exist a tracking branch in exactly one remote (call it `<remote>`) |
Eric Sunshine | 661a5a3 | 2018-02-16 15:44:51 -0500 | [diff] [blame] | 75 | with a matching name, treat as equivalent to: |
Eric Sunshine | d023df1 | 2018-02-16 15:44:52 -0500 | [diff] [blame] | 76 | + |
Thomas Gummerer | 4e85333 | 2017-11-26 19:43:54 +0000 | [diff] [blame] | 77 | ------------ |
| 78 | $ git worktree add --track -b <branch> <path> <remote>/<branch> |
| 79 | ------------ |
| 80 | + |
Ævar Arnfjörð Bjarmason | 8d7b558 | 2018-06-05 14:40:49 +0000 | [diff] [blame] | 81 | If the branch exists in multiple remotes and one of them is named by |
| 82 | the `checkout.defaultRemote` configuration variable, we'll use that |
| 83 | one for the purposes of disambiguation, even if the `<branch>` isn't |
| 84 | unique across all remotes. Set it to |
| 85 | e.g. `checkout.defaultRemote=origin` to always checkout remote |
| 86 | branches from there if `<branch>` is ambiguous but exists on the |
Eric Sunshine | e79e313 | 2020-08-03 20:55:31 -0400 | [diff] [blame] | 87 | `origin` remote. See also `checkout.defaultRemote` in |
Ævar Arnfjörð Bjarmason | 8d7b558 | 2018-06-05 14:40:49 +0000 | [diff] [blame] | 88 | linkgit:git-config[1]. |
| 89 | + |
Thomas Gummerer | c4738ae | 2017-11-26 19:43:52 +0000 | [diff] [blame] | 90 | If `<commit-ish>` is omitted and neither `-b` nor `-B` nor `--detach` used, |
Derrick Stolee | 5997014 | 2022-02-23 14:29:14 +0000 | [diff] [blame] | 91 | then, as a convenience, the new worktree is associated with a branch (call |
| 92 | it `<branch>`) named after `$(basename <path>)`. If `<branch>` doesn't |
| 93 | exist, a new branch based on `HEAD` is automatically created as if |
| 94 | `-b <branch>` was given. If `<branch>` does exist, it will be checked out |
| 95 | in the new worktree, if it's not checked out anywhere else, otherwise the |
| 96 | command will refuse to create the worktree (unless `--force` is used). |
Eric Sunshine | fc56361 | 2015-07-06 13:30:50 -0400 | [diff] [blame] | 97 | |
Michael Rappazzo | bb9c03b | 2015-10-08 13:01:05 -0400 | [diff] [blame] | 98 | list:: |
| 99 | |
Derrick Stolee | 5997014 | 2022-02-23 14:29:14 +0000 | [diff] [blame] | 100 | List details of each worktree. The main worktree is listed first, |
| 101 | followed by each of the linked worktrees. The output details include |
| 102 | whether the worktree is bare, the revision currently checked out, the |
Rafael Silva | 9b19a58 | 2021-01-27 09:03:09 +0100 | [diff] [blame] | 103 | branch currently checked out (or "detached HEAD" if none), "locked" if |
Derrick Stolee | 5997014 | 2022-02-23 14:29:14 +0000 | [diff] [blame] | 104 | the worktree is locked, "prunable" if the worktree can be pruned by the |
| 105 | `prune` command. |
Michael Rappazzo | bb9c03b | 2015-10-08 13:01:05 -0400 | [diff] [blame] | 106 | |
Nguyễn Thái Ngọc Duy | 58142c0 | 2016-06-13 19:18:24 +0700 | [diff] [blame] | 107 | lock:: |
| 108 | |
Derrick Stolee | 5997014 | 2022-02-23 14:29:14 +0000 | [diff] [blame] | 109 | If a worktree is on a portable device or network share which is not always |
| 110 | mounted, lock it to prevent its administrative files from being pruned |
| 111 | automatically. This also prevents it from being moved or deleted. |
| 112 | Optionally, specify a reason for the lock with `--reason`. |
Nguyễn Thái Ngọc Duy | 58142c0 | 2016-06-13 19:18:24 +0700 | [diff] [blame] | 113 | |
Nguyễn Thái Ngọc Duy | 9f792bb | 2018-02-12 16:49:36 +0700 | [diff] [blame] | 114 | move:: |
| 115 | |
Derrick Stolee | 5997014 | 2022-02-23 14:29:14 +0000 | [diff] [blame] | 116 | Move a worktree to a new location. Note that the main worktree or linked |
| 117 | worktrees containing submodules cannot be moved with this command. (The |
| 118 | `git worktree repair` command, however, can reestablish the connection |
| 119 | with linked worktrees if you move the main worktree manually.) |
Nguyễn Thái Ngọc Duy | 9f792bb | 2018-02-12 16:49:36 +0700 | [diff] [blame] | 120 | |
Nguyễn Thái Ngọc Duy | 7b722d9 | 2016-05-22 16:33:53 +0700 | [diff] [blame] | 121 | prune:: |
| 122 | |
Derrick Stolee | 5997014 | 2022-02-23 14:29:14 +0000 | [diff] [blame] | 123 | Prune worktree information in `$GIT_DIR/worktrees`. |
Nguyễn Thái Ngọc Duy | 7b722d9 | 2016-05-22 16:33:53 +0700 | [diff] [blame] | 124 | |
Nguyễn Thái Ngọc Duy | cc73385 | 2018-02-12 16:49:39 +0700 | [diff] [blame] | 125 | remove:: |
| 126 | |
Derrick Stolee | 5997014 | 2022-02-23 14:29:14 +0000 | [diff] [blame] | 127 | Remove a worktree. Only clean worktrees (no untracked files and no |
| 128 | modification in tracked files) can be removed. Unclean worktrees or ones |
| 129 | with submodules can be removed with `--force`. The main worktree cannot be |
| 130 | removed. |
Nguyễn Thái Ngọc Duy | cc73385 | 2018-02-12 16:49:39 +0700 | [diff] [blame] | 131 | |
Eric Sunshine | b214ab5 | 2020-08-31 02:57:58 -0400 | [diff] [blame] | 132 | repair [<path>...]:: |
Eric Sunshine | e8e1ff2 | 2020-08-27 04:21:25 -0400 | [diff] [blame] | 133 | |
Derrick Stolee | 5997014 | 2022-02-23 14:29:14 +0000 | [diff] [blame] | 134 | Repair worktree administrative files, if possible, if they have become |
| 135 | corrupted or outdated due to external factors. |
Eric Sunshine | bdd1f3e | 2020-08-31 02:57:57 -0400 | [diff] [blame] | 136 | + |
Derrick Stolee | 5997014 | 2022-02-23 14:29:14 +0000 | [diff] [blame] | 137 | For instance, if the main worktree (or bare repository) is moved, linked |
| 138 | worktrees will be unable to locate it. Running `repair` in the main |
| 139 | worktree will reestablish the connection from linked worktrees back to the |
| 140 | main worktree. |
Eric Sunshine | b214ab5 | 2020-08-31 02:57:58 -0400 | [diff] [blame] | 141 | + |
Derrick Stolee | 5997014 | 2022-02-23 14:29:14 +0000 | [diff] [blame] | 142 | Similarly, if the working tree for a linked worktree is moved without |
| 143 | using `git worktree move`, the main worktree (or bare repository) will be |
| 144 | unable to locate it. Running `repair` within the recently-moved worktree |
| 145 | will reestablish the connection. If multiple linked worktrees are moved, |
| 146 | running `repair` from any worktree with each tree's new `<path>` as an |
| 147 | argument, will reestablish the connection to all the specified paths. |
Eric Sunshine | cf76bae | 2020-12-21 03:16:01 -0500 | [diff] [blame] | 148 | + |
Derrick Stolee | 5997014 | 2022-02-23 14:29:14 +0000 | [diff] [blame] | 149 | If both the main worktree and linked worktrees have been moved manually, |
| 150 | then running `repair` in the main worktree and specifying the new `<path>` |
| 151 | of each linked worktree will reestablish all connections in both |
| 152 | directions. |
Eric Sunshine | e8e1ff2 | 2020-08-27 04:21:25 -0400 | [diff] [blame] | 153 | |
Nguyễn Thái Ngọc Duy | 6d30862 | 2016-06-13 19:18:25 +0700 | [diff] [blame] | 154 | unlock:: |
| 155 | |
Derrick Stolee | 5997014 | 2022-02-23 14:29:14 +0000 | [diff] [blame] | 156 | Unlock a worktree, allowing it to be pruned, moved or deleted. |
Nguyễn Thái Ngọc Duy | 6d30862 | 2016-06-13 19:18:25 +0700 | [diff] [blame] | 157 | |
Nguyễn Thái Ngọc Duy | df0b6cf | 2015-06-29 19:51:18 +0700 | [diff] [blame] | 158 | OPTIONS |
| 159 | ------- |
| 160 | |
Eric Sunshine | f432544 | 2015-07-06 13:30:51 -0400 | [diff] [blame] | 161 | -f:: |
| 162 | --force:: |
Derrick Stolee | 6036be1 | 2022-02-23 14:29:15 +0000 | [diff] [blame] | 163 | By default, `add` refuses to create a new worktree when |
Nguyễn Thái Ngọc Duy | cc73385 | 2018-02-12 16:49:39 +0700 | [diff] [blame] | 164 | `<commit-ish>` is a branch name and is already checked out by |
Derrick Stolee | 6036be1 | 2022-02-23 14:29:15 +0000 | [diff] [blame] | 165 | another worktree, or if `<path>` is already assigned to some |
| 166 | worktree but is missing (for instance, if `<path>` was deleted |
Eric Sunshine | e19831c | 2018-08-28 17:20:23 -0400 | [diff] [blame] | 167 | manually). This option overrides these safeguards. To add a missing but |
Derrick Stolee | 6036be1 | 2022-02-23 14:29:15 +0000 | [diff] [blame] | 168 | locked worktree path, specify `--force` twice. |
Eric Sunshine | e19831c | 2018-08-28 17:20:23 -0400 | [diff] [blame] | 169 | + |
Derrick Stolee | 6036be1 | 2022-02-23 14:29:15 +0000 | [diff] [blame] | 170 | `move` refuses to move a locked worktree unless `--force` is specified |
| 171 | twice. If the destination is already assigned to some other worktree but is |
Eric Sunshine | 810382e | 2020-06-10 02:30:49 -0400 | [diff] [blame] | 172 | missing (for instance, if `<new-path>` was deleted manually), then `--force` |
Eric Sunshine | e79e313 | 2020-08-03 20:55:31 -0400 | [diff] [blame] | 173 | allows the move to proceed; use `--force` twice if the destination is locked. |
Eric Sunshine | 68a6b3a | 2018-08-28 17:20:24 -0400 | [diff] [blame] | 174 | + |
Derrick Stolee | 6036be1 | 2022-02-23 14:29:15 +0000 | [diff] [blame] | 175 | `remove` refuses to remove an unclean worktree unless `--force` is used. |
| 176 | To remove a locked worktree, specify `--force` twice. |
Eric Sunshine | f432544 | 2015-07-06 13:30:51 -0400 | [diff] [blame] | 177 | |
Eric Sunshine | cbdf60f | 2015-07-06 13:30:53 -0400 | [diff] [blame] | 178 | -b <new-branch>:: |
| 179 | -B <new-branch>:: |
| 180 | With `add`, create a new branch named `<new-branch>` starting at |
Derrick Stolee | 6036be1 | 2022-02-23 14:29:15 +0000 | [diff] [blame] | 181 | `<commit-ish>`, and check out `<new-branch>` into the new worktree. |
Eric Sunshine | e79e313 | 2020-08-03 20:55:31 -0400 | [diff] [blame] | 182 | If `<commit-ish>` is omitted, it defaults to `HEAD`. |
Eric Sunshine | cbdf60f | 2015-07-06 13:30:53 -0400 | [diff] [blame] | 183 | By default, `-b` refuses to create a new branch if it already |
| 184 | exists. `-B` overrides this safeguard, resetting `<new-branch>` to |
Thomas Gummerer | c4738ae | 2017-11-26 19:43:52 +0000 | [diff] [blame] | 185 | `<commit-ish>`. |
Eric Sunshine | cbdf60f | 2015-07-06 13:30:53 -0400 | [diff] [blame] | 186 | |
Eric Sunshine | c670aa4 | 2020-09-06 20:02:21 -0400 | [diff] [blame] | 187 | -d:: |
Eric Sunshine | 39ecb27 | 2015-07-06 13:30:52 -0400 | [diff] [blame] | 188 | --detach:: |
Derrick Stolee | 6036be1 | 2022-02-23 14:29:15 +0000 | [diff] [blame] | 189 | With `add`, detach `HEAD` in the new worktree. See "DETACHED HEAD" |
Michael Haggerty | bc48328 | 2015-07-20 01:29:18 -0400 | [diff] [blame] | 190 | in linkgit:git-checkout[1]. |
Eric Sunshine | 39ecb27 | 2015-07-06 13:30:52 -0400 | [diff] [blame] | 191 | |
Ray Zhang | ef2a0ac | 2016-03-29 10:11:01 +0000 | [diff] [blame] | 192 | --[no-]checkout:: |
Thomas Gummerer | c4738ae | 2017-11-26 19:43:52 +0000 | [diff] [blame] | 193 | By default, `add` checks out `<commit-ish>`, however, `--no-checkout` can |
Ray Zhang | ef2a0ac | 2016-03-29 10:11:01 +0000 | [diff] [blame] | 194 | be used to suppress checkout in order to make customizations, |
| 195 | such as configuring sparse-checkout. See "Sparse checkout" |
| 196 | in linkgit:git-read-tree[1]. |
| 197 | |
Thomas Gummerer | 71d6682 | 2017-11-29 20:04:50 +0000 | [diff] [blame] | 198 | --[no-]guess-remote:: |
| 199 | With `worktree add <path>`, without `<commit-ish>`, instead |
Eric Sunshine | e79e313 | 2020-08-03 20:55:31 -0400 | [diff] [blame] | 200 | of creating a new branch from `HEAD`, if there exists a tracking |
Ralf Thielow | 50fdf7b | 2018-01-11 19:18:21 +0100 | [diff] [blame] | 201 | branch in exactly one remote matching the basename of `<path>`, |
Thomas Gummerer | 71d6682 | 2017-11-29 20:04:50 +0000 | [diff] [blame] | 202 | base the new branch on the remote-tracking branch, and mark |
| 203 | the remote-tracking branch as "upstream" from the new branch. |
Thomas Gummerer | e92445a | 2017-11-29 20:04:51 +0000 | [diff] [blame] | 204 | + |
| 205 | This can also be set up as the default behaviour by using the |
| 206 | `worktree.guessRemote` config option. |
Thomas Gummerer | 71d6682 | 2017-11-29 20:04:50 +0000 | [diff] [blame] | 207 | |
Thomas Gummerer | e284e89 | 2017-11-26 19:43:53 +0000 | [diff] [blame] | 208 | --[no-]track:: |
| 209 | When creating a new branch, if `<commit-ish>` is a branch, |
| 210 | mark it as "upstream" from the new branch. This is the |
| 211 | default if `<commit-ish>` is a remote-tracking branch. See |
Eric Sunshine | e79e313 | 2020-08-03 20:55:31 -0400 | [diff] [blame] | 212 | `--track` in linkgit:git-branch[1] for details. |
Thomas Gummerer | e284e89 | 2017-11-26 19:43:53 +0000 | [diff] [blame] | 213 | |
Nguyễn Thái Ngọc Duy | 507e6e9 | 2017-04-12 20:58:05 +0700 | [diff] [blame] | 214 | --lock:: |
Derrick Stolee | 6036be1 | 2022-02-23 14:29:15 +0000 | [diff] [blame] | 215 | Keep the worktree locked after creation. This is the |
Nguyễn Thái Ngọc Duy | 507e6e9 | 2017-04-12 20:58:05 +0700 | [diff] [blame] | 216 | equivalent of `git worktree lock` after `git worktree add`, |
Eric Sunshine | ff1ce50 | 2020-08-03 20:55:33 -0400 | [diff] [blame] | 217 | but without a race condition. |
Nguyễn Thái Ngọc Duy | 507e6e9 | 2017-04-12 20:58:05 +0700 | [diff] [blame] | 218 | |
Nguyễn Thái Ngọc Duy | df0b6cf | 2015-06-29 19:51:18 +0700 | [diff] [blame] | 219 | -n:: |
| 220 | --dry-run:: |
Eric Sunshine | 4f09825 | 2015-07-06 13:30:39 -0400 | [diff] [blame] | 221 | With `prune`, do not remove anything; just report what it would |
Nguyễn Thái Ngọc Duy | df0b6cf | 2015-06-29 19:51:18 +0700 | [diff] [blame] | 222 | remove. |
| 223 | |
Michael Rappazzo | bb9c03b | 2015-10-08 13:01:05 -0400 | [diff] [blame] | 224 | --porcelain:: |
| 225 | With `list`, output in an easy-to-parse format for scripts. |
| 226 | This format will remain stable across Git versions and regardless of user |
Phillip Wood | d97eb30 | 2022-03-31 16:21:28 +0000 | [diff] [blame] | 227 | configuration. It is recommended to combine this with `-z`. |
| 228 | See below for details. |
| 229 | |
| 230 | -z:: |
| 231 | Terminate each line with a NUL rather than a newline when |
| 232 | `--porcelain` is specified with `list`. This makes it possible |
| 233 | to parse the output when a worktree path contains a newline |
| 234 | character. |
Michael Rappazzo | bb9c03b | 2015-10-08 13:01:05 -0400 | [diff] [blame] | 235 | |
Elia Pinto | 371979c | 2018-08-15 20:56:30 +0000 | [diff] [blame] | 236 | -q:: |
| 237 | --quiet:: |
Eric Sunshine | e79e313 | 2020-08-03 20:55:31 -0400 | [diff] [blame] | 238 | With `add`, suppress feedback messages. |
Elia Pinto | 371979c | 2018-08-15 20:56:30 +0000 | [diff] [blame] | 239 | |
Nguyễn Thái Ngọc Duy | df0b6cf | 2015-06-29 19:51:18 +0700 | [diff] [blame] | 240 | -v:: |
| 241 | --verbose:: |
Eric Sunshine | 4f09825 | 2015-07-06 13:30:39 -0400 | [diff] [blame] | 242 | With `prune`, report all removals. |
Rafael Silva | 076b444 | 2021-01-27 09:03:10 +0100 | [diff] [blame] | 243 | + |
| 244 | With `list`, output additional information about worktrees (see below). |
Nguyễn Thái Ngọc Duy | df0b6cf | 2015-06-29 19:51:18 +0700 | [diff] [blame] | 245 | |
| 246 | --expire <time>:: |
Derrick Stolee | 6036be1 | 2022-02-23 14:29:15 +0000 | [diff] [blame] | 247 | With `prune`, only expire unused worktrees older than `<time>`. |
Rafael Silva | 9b19a58 | 2021-01-27 09:03:09 +0100 | [diff] [blame] | 248 | + |
Derrick Stolee | 6036be1 | 2022-02-23 14:29:15 +0000 | [diff] [blame] | 249 | With `list`, annotate missing worktrees as prunable if they are older than |
| 250 | `<time>`. |
Nguyễn Thái Ngọc Duy | df0b6cf | 2015-06-29 19:51:18 +0700 | [diff] [blame] | 251 | |
Nguyễn Thái Ngọc Duy | 58142c0 | 2016-06-13 19:18:24 +0700 | [diff] [blame] | 252 | --reason <string>:: |
Derrick Stolee | 6036be1 | 2022-02-23 14:29:15 +0000 | [diff] [blame] | 253 | With `lock` or with `add --lock`, an explanation why the worktree |
| 254 | is locked. |
Nguyễn Thái Ngọc Duy | 58142c0 | 2016-06-13 19:18:24 +0700 | [diff] [blame] | 255 | |
| 256 | <worktree>:: |
Derrick Stolee | 6036be1 | 2022-02-23 14:29:15 +0000 | [diff] [blame] | 257 | Worktrees can be identified by path, either relative or absolute. |
Nguyễn Thái Ngọc Duy | 080739b | 2016-06-13 19:18:26 +0700 | [diff] [blame] | 258 | + |
Derrick Stolee | 6036be1 | 2022-02-23 14:29:15 +0000 | [diff] [blame] | 259 | If the last path components in the worktree's path is unique among |
| 260 | worktrees, it can be used to identify a worktree. For example if you only |
| 261 | have two worktrees, at `/abc/def/ghi` and `/abc/def/ggg`, then `ghi` or |
| 262 | `def/ghi` is enough to point to the former worktree. |
Nguyễn Thái Ngọc Duy | 58142c0 | 2016-06-13 19:18:24 +0700 | [diff] [blame] | 263 | |
Nguyễn Thái Ngọc Duy | 8aff1a9 | 2018-09-29 21:10:23 +0200 | [diff] [blame] | 264 | REFS |
| 265 | ---- |
Derrick Stolee | a777d4c | 2022-02-23 14:29:16 +0000 | [diff] [blame] | 266 | When using multiple worktrees, some refs are shared between all worktrees, |
| 267 | but others are specific to an individual worktree. One example is `HEAD`, |
| 268 | which is different for each worktree. This section is about the sharing |
| 269 | rules and how to access refs of one worktree from another. |
Nguyễn Thái Ngọc Duy | 8aff1a9 | 2018-09-29 21:10:23 +0200 | [diff] [blame] | 270 | |
Derrick Stolee | a777d4c | 2022-02-23 14:29:16 +0000 | [diff] [blame] | 271 | In general, all pseudo refs are per-worktree and all refs starting with |
| 272 | `refs/` are shared. Pseudo refs are ones like `HEAD` which are directly |
| 273 | under `$GIT_DIR` instead of inside `$GIT_DIR/refs`. There are exceptions, |
| 274 | however: refs inside `refs/bisect` and `refs/worktree` are not shared. |
Nguyễn Thái Ngọc Duy | 8aff1a9 | 2018-09-29 21:10:23 +0200 | [diff] [blame] | 275 | |
Derrick Stolee | a777d4c | 2022-02-23 14:29:16 +0000 | [diff] [blame] | 276 | Refs that are per-worktree can still be accessed from another worktree via |
| 277 | two special paths, `main-worktree` and `worktrees`. The former gives |
| 278 | access to per-worktree refs of the main worktree, while the latter to all |
| 279 | linked worktrees. |
Nguyễn Thái Ngọc Duy | 3a3b9d8 | 2018-10-21 10:08:54 +0200 | [diff] [blame] | 280 | |
Eric Sunshine | e79e313 | 2020-08-03 20:55:31 -0400 | [diff] [blame] | 281 | For example, `main-worktree/HEAD` or `main-worktree/refs/bisect/good` |
Derrick Stolee | a777d4c | 2022-02-23 14:29:16 +0000 | [diff] [blame] | 282 | resolve to the same value as the main worktree's `HEAD` and |
Eric Sunshine | e79e313 | 2020-08-03 20:55:31 -0400 | [diff] [blame] | 283 | `refs/bisect/good` respectively. Similarly, `worktrees/foo/HEAD` or |
| 284 | `worktrees/bar/refs/bisect/bad` are the same as |
| 285 | `$GIT_COMMON_DIR/worktrees/foo/HEAD` and |
| 286 | `$GIT_COMMON_DIR/worktrees/bar/refs/bisect/bad`. |
Nguyễn Thái Ngọc Duy | 3a3b9d8 | 2018-10-21 10:08:54 +0200 | [diff] [blame] | 287 | |
Eric Sunshine | e79e313 | 2020-08-03 20:55:31 -0400 | [diff] [blame] | 288 | To access refs, it's best not to look inside `$GIT_DIR` directly. Instead |
Nguyễn Thái Ngọc Duy | 14f74d5 | 2018-11-03 06:14:18 +0100 | [diff] [blame] | 289 | use commands such as linkgit:git-rev-parse[1] or linkgit:git-update-ref[1] |
Nguyễn Thái Ngọc Duy | 8aff1a9 | 2018-09-29 21:10:23 +0200 | [diff] [blame] | 290 | which will handle refs correctly. |
| 291 | |
Nguyễn Thái Ngọc Duy | 58b284a | 2018-10-21 16:02:28 +0200 | [diff] [blame] | 292 | CONFIGURATION FILE |
| 293 | ------------------ |
Derrick Stolee | 7b21582 | 2022-02-23 14:29:17 +0000 | [diff] [blame] | 294 | By default, the repository `config` file is shared across all worktrees. |
| 295 | If the config variables `core.bare` or `core.worktree` are present in the |
| 296 | common config file and `extensions.worktreeConfig` is disabled, then they |
| 297 | will be applied to the main worktree only. |
Nguyễn Thái Ngọc Duy | 58b284a | 2018-10-21 16:02:28 +0200 | [diff] [blame] | 298 | |
Derrick Stolee | 7b21582 | 2022-02-23 14:29:17 +0000 | [diff] [blame] | 299 | In order to have worktree-specific configuration, you can turn on the |
| 300 | `worktreeConfig` extension, e.g.: |
Nguyễn Thái Ngọc Duy | 58b284a | 2018-10-21 16:02:28 +0200 | [diff] [blame] | 301 | |
| 302 | ------------ |
| 303 | $ git config extensions.worktreeConfig true |
| 304 | ------------ |
| 305 | |
| 306 | In this mode, specific configuration stays in the path pointed by `git |
| 307 | rev-parse --git-path config.worktree`. You can add or update |
| 308 | configuration in this file with `git config --worktree`. Older Git |
| 309 | versions will refuse to access repositories with this extension. |
| 310 | |
| 311 | Note that in this file, the exception for `core.bare` and `core.worktree` |
Eric Sunshine | ff1ce50 | 2020-08-03 20:55:33 -0400 | [diff] [blame] | 312 | is gone. If they exist in `$GIT_DIR/config`, you must move |
Derrick Stolee | 7b21582 | 2022-02-23 14:29:17 +0000 | [diff] [blame] | 313 | them to the `config.worktree` of the main worktree. You may also take this |
| 314 | opportunity to review and move other configuration that you do not want to |
| 315 | share to all worktrees: |
Nguyễn Thái Ngọc Duy | 58b284a | 2018-10-21 16:02:28 +0200 | [diff] [blame] | 316 | |
Derrick Stolee | 5c11c0d | 2022-02-07 21:32:58 +0000 | [diff] [blame] | 317 | - `core.worktree` should never be shared. |
| 318 | |
| 319 | - `core.bare` should not be shared if the value is `core.bare=true`. |
Nguyễn Thái Ngọc Duy | 58b284a | 2018-10-21 16:02:28 +0200 | [diff] [blame] | 320 | |
Derrick Stolee | 7b21582 | 2022-02-23 14:29:17 +0000 | [diff] [blame] | 321 | - `core.sparseCheckout` should not be shared, unless you are sure you |
| 322 | always use sparse checkout for all worktrees. |
Nguyễn Thái Ngọc Duy | 58b284a | 2018-10-21 16:02:28 +0200 | [diff] [blame] | 323 | |
Derrick Stolee | 5c11c0d | 2022-02-07 21:32:58 +0000 | [diff] [blame] | 324 | See the documentation of `extensions.worktreeConfig` in |
| 325 | linkgit:git-config[1] for more details. |
| 326 | |
Eric Sunshine | af189b4 | 2015-07-06 13:30:42 -0400 | [diff] [blame] | 327 | DETAILS |
| 328 | ------- |
Derrick Stolee | f13a146 | 2022-02-23 14:29:18 +0000 | [diff] [blame] | 329 | Each linked worktree has a private sub-directory in the repository's |
Eric Sunshine | e79e313 | 2020-08-03 20:55:31 -0400 | [diff] [blame] | 330 | `$GIT_DIR/worktrees` directory. The private sub-directory's name is usually |
Derrick Stolee | f13a146 | 2022-02-23 14:29:18 +0000 | [diff] [blame] | 331 | the base name of the linked worktree's path, possibly appended with a |
Eric Sunshine | af189b4 | 2015-07-06 13:30:42 -0400 | [diff] [blame] | 332 | number to make it unique. For example, when `$GIT_DIR=/path/main/.git` the |
Eric Sunshine | 4d5a3c5 | 2015-07-16 18:09:43 -0400 | [diff] [blame] | 333 | command `git worktree add /path/other/test-next next` creates the linked |
Derrick Stolee | f13a146 | 2022-02-23 14:29:18 +0000 | [diff] [blame] | 334 | worktree in `/path/other/test-next` and also creates a |
Eric Sunshine | af189b4 | 2015-07-06 13:30:42 -0400 | [diff] [blame] | 335 | `$GIT_DIR/worktrees/test-next` directory (or `$GIT_DIR/worktrees/test-next1` |
| 336 | if `test-next` is already taken). |
| 337 | |
Derrick Stolee | f13a146 | 2022-02-23 14:29:18 +0000 | [diff] [blame] | 338 | Within a linked worktree, `$GIT_DIR` is set to point to this private |
Eric Sunshine | af189b4 | 2015-07-06 13:30:42 -0400 | [diff] [blame] | 339 | directory (e.g. `/path/main/.git/worktrees/test-next` in the example) and |
Derrick Stolee | f13a146 | 2022-02-23 14:29:18 +0000 | [diff] [blame] | 340 | `$GIT_COMMON_DIR` is set to point back to the main worktree's `$GIT_DIR` |
Eric Sunshine | af189b4 | 2015-07-06 13:30:42 -0400 | [diff] [blame] | 341 | (e.g. `/path/main/.git`). These settings are made in a `.git` file located at |
Derrick Stolee | f13a146 | 2022-02-23 14:29:18 +0000 | [diff] [blame] | 342 | the top directory of the linked worktree. |
Eric Sunshine | af189b4 | 2015-07-06 13:30:42 -0400 | [diff] [blame] | 343 | |
| 344 | Path resolution via `git rev-parse --git-path` uses either |
Eric Sunshine | e79e313 | 2020-08-03 20:55:31 -0400 | [diff] [blame] | 345 | `$GIT_DIR` or `$GIT_COMMON_DIR` depending on the path. For example, in the |
Derrick Stolee | f13a146 | 2022-02-23 14:29:18 +0000 | [diff] [blame] | 346 | linked worktree `git rev-parse --git-path HEAD` returns |
Eric Sunshine | af189b4 | 2015-07-06 13:30:42 -0400 | [diff] [blame] | 347 | `/path/main/.git/worktrees/test-next/HEAD` (not |
| 348 | `/path/other/test-next/.git/HEAD` or `/path/main/.git/HEAD`) while `git |
| 349 | rev-parse --git-path refs/heads/master` uses |
Eric Sunshine | e79e313 | 2020-08-03 20:55:31 -0400 | [diff] [blame] | 350 | `$GIT_COMMON_DIR` and returns `/path/main/.git/refs/heads/master`, |
Derrick Stolee | f13a146 | 2022-02-23 14:29:18 +0000 | [diff] [blame] | 351 | since refs are shared across all worktrees, except `refs/bisect` and |
Eric Sunshine | e79e313 | 2020-08-03 20:55:31 -0400 | [diff] [blame] | 352 | `refs/worktree`. |
Eric Sunshine | af189b4 | 2015-07-06 13:30:42 -0400 | [diff] [blame] | 353 | |
| 354 | See linkgit:gitrepository-layout[5] for more information. The rule of |
| 355 | thumb is do not make any assumption about whether a path belongs to |
Eric Sunshine | e79e313 | 2020-08-03 20:55:31 -0400 | [diff] [blame] | 356 | `$GIT_DIR` or `$GIT_COMMON_DIR` when you need to directly access something |
| 357 | inside `$GIT_DIR`. Use `git rev-parse --git-path` to get the final path. |
Eric Sunshine | af189b4 | 2015-07-06 13:30:42 -0400 | [diff] [blame] | 358 | |
Derrick Stolee | f13a146 | 2022-02-23 14:29:18 +0000 | [diff] [blame] | 359 | If you manually move a linked worktree, you need to update the `gitdir` file |
| 360 | in the entry's directory. For example, if a linked worktree is moved |
Nguyễn Thái Ngọc Duy | 618244e | 2016-01-22 15:35:49 +0700 | [diff] [blame] | 361 | to `/newpath/test-next` and its `.git` file points to |
| 362 | `/path/main/.git/worktrees/test-next`, then update |
| 363 | `/path/main/.git/worktrees/test-next/gitdir` to reference `/newpath/test-next` |
Eric Sunshine | b214ab5 | 2020-08-31 02:57:58 -0400 | [diff] [blame] | 364 | instead. Better yet, run `git worktree repair` to reestablish the connection |
| 365 | automatically. |
Nguyễn Thái Ngọc Duy | 618244e | 2016-01-22 15:35:49 +0700 | [diff] [blame] | 366 | |
Eric Sunshine | e79e313 | 2020-08-03 20:55:31 -0400 | [diff] [blame] | 367 | To prevent a `$GIT_DIR/worktrees` entry from being pruned (which |
Eric Sunshine | a8ba5dd | 2015-07-06 13:30:43 -0400 | [diff] [blame] | 368 | can be useful in some situations, such as when the |
Derrick Stolee | f13a146 | 2022-02-23 14:29:18 +0000 | [diff] [blame] | 369 | entry's worktree is stored on a portable device), use the |
Nguyễn Thái Ngọc Duy | 58142c0 | 2016-06-13 19:18:24 +0700 | [diff] [blame] | 370 | `git worktree lock` command, which adds a file named |
Eric Sunshine | e79e313 | 2020-08-03 20:55:31 -0400 | [diff] [blame] | 371 | `locked` to the entry's directory. The file contains the reason in |
Derrick Stolee | f13a146 | 2022-02-23 14:29:18 +0000 | [diff] [blame] | 372 | plain text. For example, if a linked worktree's `.git` file points |
Eric Sunshine | a8ba5dd | 2015-07-06 13:30:43 -0400 | [diff] [blame] | 373 | to `/path/main/.git/worktrees/test-next` then a file named |
| 374 | `/path/main/.git/worktrees/test-next/locked` will prevent the |
| 375 | `test-next` entry from being pruned. See |
| 376 | linkgit:gitrepository-layout[5] for details. |
| 377 | |
Eric Sunshine | e79e313 | 2020-08-03 20:55:31 -0400 | [diff] [blame] | 378 | When `extensions.worktreeConfig` is enabled, the config file |
Nguyễn Thái Ngọc Duy | 58b284a | 2018-10-21 16:02:28 +0200 | [diff] [blame] | 379 | `.git/worktrees/<id>/config.worktree` is read after `.git/config` is. |
| 380 | |
Michael Rappazzo | bb9c03b | 2015-10-08 13:01:05 -0400 | [diff] [blame] | 381 | LIST OUTPUT FORMAT |
| 382 | ------------------ |
Eric Sunshine | e79e313 | 2020-08-03 20:55:31 -0400 | [diff] [blame] | 383 | The `worktree list` command has two output formats. The default format shows the |
Michael Rappazzo | bb9c03b | 2015-10-08 13:01:05 -0400 | [diff] [blame] | 384 | details on a single line with columns. For example: |
| 385 | |
| 386 | ------------ |
Eric Sunshine | 22d11a6 | 2018-04-09 03:34:00 -0400 | [diff] [blame] | 387 | $ git worktree list |
Michael Rappazzo | bb9c03b | 2015-10-08 13:01:05 -0400 | [diff] [blame] | 388 | /path/to/bare-source (bare) |
| 389 | /path/to/linked-worktree abcd1234 [master] |
| 390 | /path/to/other-linked-worktree 1234abc (detached HEAD) |
| 391 | ------------ |
| 392 | |
Derrick Stolee | 07d8538 | 2022-02-23 14:29:19 +0000 | [diff] [blame] | 393 | The command also shows annotations for each worktree, according to its state. |
Rafael Silva | 9b19a58 | 2021-01-27 09:03:09 +0100 | [diff] [blame] | 394 | These annotations are: |
| 395 | |
Derrick Stolee | 07d8538 | 2022-02-23 14:29:19 +0000 | [diff] [blame] | 396 | * `locked`, if the worktree is locked. |
| 397 | * `prunable`, if the worktree can be pruned via `git worktree prune`. |
Rafael Silva | 9b19a58 | 2021-01-27 09:03:09 +0100 | [diff] [blame] | 398 | |
| 399 | ------------ |
| 400 | $ git worktree list |
| 401 | /path/to/linked-worktree abcd1234 [master] |
Andrei Rybak | 98c7656 | 2021-06-25 21:38:51 +0200 | [diff] [blame] | 402 | /path/to/locked-worktree acbd5678 (brancha) locked |
Rafael Silva | 9b19a58 | 2021-01-27 09:03:09 +0100 | [diff] [blame] | 403 | /path/to/prunable-worktree 5678abc (detached HEAD) prunable |
| 404 | ------------ |
| 405 | |
Rafael Silva | 076b444 | 2021-01-27 09:03:10 +0100 | [diff] [blame] | 406 | For these annotations, a reason might also be available and this can be |
| 407 | seen using the verbose mode. The annotation is then moved to the next line |
| 408 | indented followed by the additional information. |
| 409 | |
| 410 | ------------ |
| 411 | $ git worktree list --verbose |
| 412 | /path/to/linked-worktree abcd1234 [master] |
| 413 | /path/to/locked-worktree-no-reason abcd5678 (detached HEAD) locked |
| 414 | /path/to/locked-worktree-with-reason 1234abcd (brancha) |
Derrick Stolee | 07d8538 | 2022-02-23 14:29:19 +0000 | [diff] [blame] | 415 | locked: worktree path is mounted on a portable device |
Rafael Silva | 076b444 | 2021-01-27 09:03:10 +0100 | [diff] [blame] | 416 | /path/to/prunable-worktree 5678abc1 (detached HEAD) |
| 417 | prunable: gitdir file points to non-existent location |
| 418 | ------------ |
| 419 | |
| 420 | Note that the annotation is moved to the next line if the additional |
| 421 | information is available, otherwise it stays on the same line as the |
Derrick Stolee | 07d8538 | 2022-02-23 14:29:19 +0000 | [diff] [blame] | 422 | worktree itself. |
Rafael Silva | 076b444 | 2021-01-27 09:03:10 +0100 | [diff] [blame] | 423 | |
Michael Rappazzo | bb9c03b | 2015-10-08 13:01:05 -0400 | [diff] [blame] | 424 | Porcelain Format |
| 425 | ~~~~~~~~~~~~~~~~ |
Phillip Wood | d97eb30 | 2022-03-31 16:21:28 +0000 | [diff] [blame] | 426 | The porcelain format has a line per attribute. If `-z` is given then the lines |
| 427 | are terminated with NUL rather than a newline. Attributes are listed with a |
Eric Sunshine | e79e313 | 2020-08-03 20:55:31 -0400 | [diff] [blame] | 428 | label and value separated by a single space. Boolean attributes (like `bare` |
Eric Sunshine | ff1ce50 | 2020-08-03 20:55:33 -0400 | [diff] [blame] | 429 | and `detached`) are listed as a label only, and are present only |
Rafael Silva | 862c723 | 2021-01-27 09:03:08 +0100 | [diff] [blame] | 430 | if the value is true. Some attributes (like `locked`) can be listed as a label |
| 431 | only or with a value depending upon whether a reason is available. The first |
Derrick Stolee | 07d8538 | 2022-02-23 14:29:19 +0000 | [diff] [blame] | 432 | attribute of a worktree is always `worktree`, an empty line indicates the |
Rafael Silva | 862c723 | 2021-01-27 09:03:08 +0100 | [diff] [blame] | 433 | end of the record. For example: |
Michael Rappazzo | bb9c03b | 2015-10-08 13:01:05 -0400 | [diff] [blame] | 434 | |
| 435 | ------------ |
Eric Sunshine | 22d11a6 | 2018-04-09 03:34:00 -0400 | [diff] [blame] | 436 | $ git worktree list --porcelain |
Michael Rappazzo | bb9c03b | 2015-10-08 13:01:05 -0400 | [diff] [blame] | 437 | worktree /path/to/bare-source |
| 438 | bare |
| 439 | |
| 440 | worktree /path/to/linked-worktree |
| 441 | HEAD abcd1234abcd1234abcd1234abcd1234abcd1234 |
| 442 | branch refs/heads/master |
| 443 | |
| 444 | worktree /path/to/other-linked-worktree |
| 445 | HEAD 1234abc1234abc1234abc1234abc1234abc1234a |
| 446 | detached |
| 447 | |
Rafael Silva | 862c723 | 2021-01-27 09:03:08 +0100 | [diff] [blame] | 448 | worktree /path/to/linked-worktree-locked-no-reason |
| 449 | HEAD 5678abc5678abc5678abc5678abc5678abc5678c |
| 450 | branch refs/heads/locked-no-reason |
| 451 | locked |
| 452 | |
| 453 | worktree /path/to/linked-worktree-locked-with-reason |
| 454 | HEAD 3456def3456def3456def3456def3456def3456b |
| 455 | branch refs/heads/locked-with-reason |
| 456 | locked reason why is locked |
| 457 | |
Rafael Silva | 9b19a58 | 2021-01-27 09:03:09 +0100 | [diff] [blame] | 458 | worktree /path/to/linked-worktree-prunable |
| 459 | HEAD 1233def1234def1234def1234def1234def1234b |
| 460 | detached |
| 461 | prunable gitdir file points to non-existent location |
| 462 | |
Rafael Silva | 862c723 | 2021-01-27 09:03:08 +0100 | [diff] [blame] | 463 | ------------ |
| 464 | |
Phillip Wood | d97eb30 | 2022-03-31 16:21:28 +0000 | [diff] [blame] | 465 | Unless `-z` is used any "unusual" characters in the lock reason such as newlines |
Rafael Silva | 862c723 | 2021-01-27 09:03:08 +0100 | [diff] [blame] | 466 | are escaped and the entire reason is quoted as explained for the |
| 467 | configuration variable `core.quotePath` (see linkgit:git-config[1]). |
| 468 | For Example: |
| 469 | |
| 470 | ------------ |
| 471 | $ git worktree list --porcelain |
| 472 | ... |
| 473 | locked "reason\nwhy is locked" |
| 474 | ... |
Michael Rappazzo | bb9c03b | 2015-10-08 13:01:05 -0400 | [diff] [blame] | 475 | ------------ |
| 476 | |
Eric Sunshine | 9645459 | 2015-07-06 13:30:44 -0400 | [diff] [blame] | 477 | EXAMPLES |
| 478 | -------- |
| 479 | You are in the middle of a refactoring session and your boss comes in and |
| 480 | demands that you fix something immediately. You might typically use |
| 481 | linkgit:git-stash[1] to store your changes away temporarily, however, your |
Michael Haggerty | bc48328 | 2015-07-20 01:29:18 -0400 | [diff] [blame] | 482 | working tree is in such a state of disarray (with new, moved, and removed |
| 483 | files, and other bits and pieces strewn around) that you don't want to risk |
Derrick Stolee | 07d8538 | 2022-02-23 14:29:19 +0000 | [diff] [blame] | 484 | disturbing any of it. Instead, you create a temporary linked worktree to |
Eric Sunshine | 9645459 | 2015-07-06 13:30:44 -0400 | [diff] [blame] | 485 | make the emergency fix, remove it when done, and then resume your earlier |
| 486 | refactoring session. |
| 487 | |
| 488 | ------------ |
Eric Sunshine | cbdf60f | 2015-07-06 13:30:53 -0400 | [diff] [blame] | 489 | $ git worktree add -b emergency-fix ../temp master |
Eric Sunshine | 9645459 | 2015-07-06 13:30:44 -0400 | [diff] [blame] | 490 | $ pushd ../temp |
| 491 | # ... hack hack hack ... |
| 492 | $ git commit -a -m 'emergency fix for boss' |
| 493 | $ popd |
Eric Sunshine | 3f0b42b | 2018-04-09 03:33:59 -0400 | [diff] [blame] | 494 | $ git worktree remove ../temp |
Eric Sunshine | 9645459 | 2015-07-06 13:30:44 -0400 | [diff] [blame] | 495 | ------------ |
| 496 | |
Eric Sunshine | 6d3824c | 2015-07-06 13:30:41 -0400 | [diff] [blame] | 497 | BUGS |
| 498 | ---- |
Junio C Hamano | 18b22db | 2015-07-16 15:59:48 -0700 | [diff] [blame] | 499 | Multiple checkout in general is still experimental, and the support |
| 500 | for submodules is incomplete. It is NOT recommended to make multiple |
| 501 | checkouts of a superproject. |
Eric Sunshine | 6d3824c | 2015-07-06 13:30:41 -0400 | [diff] [blame] | 502 | |
Nguyễn Thái Ngọc Duy | df0b6cf | 2015-06-29 19:51:18 +0700 | [diff] [blame] | 503 | GIT |
| 504 | --- |
| 505 | Part of the linkgit:git[1] suite |