logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

git-worktree.1 (25447B)


  1. '\" t
  2. .\" Title: git-worktree
  3. .\" Author: [FIXME: author] [see http://www.docbook.org/tdg5/en/html/author]
  4. .\" Generator: DocBook XSL Stylesheets v1.79.2 <http://docbook.sf.net/>
  5. .\" Date: 2025-03-14
  6. .\" Manual: Git Manual
  7. .\" Source: Git 2.49.0
  8. .\" Language: English
  9. .\"
  10. .TH "GIT\-WORKTREE" "1" "2025-03-14" "Git 2\&.49\&.0" "Git Manual"
  11. .\" -----------------------------------------------------------------
  12. .\" * Define some portability stuff
  13. .\" -----------------------------------------------------------------
  14. .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  15. .\" http://bugs.debian.org/507673
  16. .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
  17. .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  18. .ie \n(.g .ds Aq \(aq
  19. .el .ds Aq '
  20. .\" -----------------------------------------------------------------
  21. .\" * set default formatting
  22. .\" -----------------------------------------------------------------
  23. .\" disable hyphenation
  24. .nh
  25. .\" disable justification (adjust text to left margin only)
  26. .ad l
  27. .\" -----------------------------------------------------------------
  28. .\" * MAIN CONTENT STARTS HERE *
  29. .\" -----------------------------------------------------------------
  30. .SH "NAME"
  31. git-worktree \- Manage multiple working trees
  32. .SH "SYNOPSIS"
  33. .sp
  34. .nf
  35. \fIgit worktree add\fR [\-f] [\-\-detach] [\-\-checkout] [\-\-lock [\-\-reason <string>]]
  36. [\-\-orphan] [(\-b | \-B) <new\-branch>] <path> [<commit\-ish>]
  37. \fIgit worktree list\fR [\-v | \-\-porcelain [\-z]]
  38. \fIgit worktree lock\fR [\-\-reason <string>] <worktree>
  39. \fIgit worktree move\fR <worktree> <new\-path>
  40. \fIgit worktree prune\fR [\-n] [\-v] [\-\-expire <expire>]
  41. \fIgit worktree remove\fR [\-f] <worktree>
  42. \fIgit worktree repair\fR [<path>\&...\:]
  43. \fIgit worktree unlock\fR <worktree>
  44. .fi
  45. .SH "DESCRIPTION"
  46. .sp
  47. Manage multiple working trees attached to the same repository\&.
  48. .sp
  49. A git repository can support multiple working trees, allowing you to check out more than one branch at a time\&. With \fBgit\fR \fBworktree\fR \fBadd\fR a new working tree is associated with the repository, along with additional metadata that differentiates that working tree from others in the same repository\&. The working tree, along with this metadata, is called a "worktree"\&.
  50. .sp
  51. This new worktree is called a "linked worktree" as opposed to the "main worktree" prepared by \fBgit-init\fR(1) or \fBgit-clone\fR(1)\&. A repository has one main worktree (if it\(cqs not a bare repository) and zero or more linked worktrees\&. When you are done with a linked worktree, remove it with \fBgit\fR \fBworktree\fR \fBremove\fR\&.
  52. .sp
  53. In its simplest form, \fBgit\fR \fBworktree\fR \fBadd\fR \fI<path>\fR automatically creates a new branch whose name is the final component of \fI<path>\fR, which is convenient if you plan to work on a new topic\&. For instance, \fBgit\fR \fBworktree\fR \fBadd\fR \fB\&.\&.\fR\fB/hotfix\fR creates new branch \fBhotfix\fR and checks it out at path \fB\&.\&.\fR\fB/hotfix\fR\&. To instead work on an existing branch in a new worktree, use \fBgit\fR \fBworktree\fR \fBadd\fR \fI<path>\fR \fI<branch>\fR\&. On the other hand, if you just plan to make some experimental changes or do testing without disturbing existing development, it is often convenient to create a \fIthrowaway\fR worktree not associated with any branch\&. For instance, \fBgit\fR \fBworktree\fR \fBadd\fR \fB\-d\fR \fI<path>\fR creates a new worktree with a detached \fBHEAD\fR at the same commit as the current branch\&.
  54. .sp
  55. If a working tree is deleted without using \fBgit\fR \fBworktree\fR \fBremove\fR, then its associated administrative files, which reside in the repository (see "DETAILS" below), will eventually be removed automatically (see \fBgc\&.worktreePruneExpire\fR in \fBgit-config\fR(1)), or you can run \fBgit\fR \fBworktree\fR \fBprune\fR in the main or any linked worktree to clean up any stale administrative files\&.
  56. .sp
  57. If the working tree for a linked worktree is stored on a portable device or network share which is not always mounted, you can prevent its administrative files from being pruned by issuing the \fBgit\fR \fBworktree\fR \fBlock\fR command, optionally specifying \fB\-\-reason\fR to explain why the worktree is locked\&.
  58. .SH "COMMANDS"
  59. .PP
  60. add <path> [<commit\-ish>]
  61. .RS 4
  62. Create a worktree at
  63. \fI<path>\fR
  64. and checkout
  65. \fI<commit\-ish>\fR
  66. into it\&. The new worktree is linked to the current repository, sharing everything except per\-worktree files such as
  67. \fBHEAD\fR,
  68. \fBindex\fR, etc\&. As a convenience,
  69. \fI<commit\-ish>\fR
  70. may be a bare "\fB\-\fR", which is synonymous with
  71. \fB@\fR{\-1}\&.
  72. .sp
  73. If
  74. \fI<commit\-ish>\fR
  75. is a branch name (call it
  76. \fI<branch>\fR) and is not found, and neither
  77. \fB\-b\fR
  78. nor
  79. \fB\-B\fR
  80. nor
  81. \fB\-\-detach\fR
  82. are used, but there does exist a tracking branch in exactly one remote (call it
  83. \fI<remote>\fR) with a matching name, treat as equivalent to:
  84. .sp
  85. .if n \{\
  86. .RS 4
  87. .\}
  88. .nf
  89. $ git worktree add \-\-track \-b <branch> <path> <remote>/<branch>
  90. .fi
  91. .if n \{\
  92. .RE
  93. .\}
  94. .sp
  95. If the branch exists in multiple remotes and one of them is named by the
  96. \fBcheckout\&.defaultRemote\fR
  97. configuration variable, we\(cqll use that one for the purposes of disambiguation, even if the
  98. \fI<branch>\fR
  99. isn\(cqt unique across all remotes\&. Set it to e\&.g\&.
  100. \fBcheckout\&.defaultRemote=origin\fR
  101. to always checkout remote branches from there if
  102. \fI<branch>\fR
  103. is ambiguous but exists on the
  104. \fBorigin\fR
  105. remote\&. See also
  106. \fBcheckout\&.defaultRemote\fR
  107. in
  108. \fBgit-config\fR(1)\&.
  109. .sp
  110. If
  111. \fI<commit\-ish>\fR
  112. is omitted and neither
  113. \fB\-b\fR
  114. nor
  115. \fB\-B\fR
  116. nor
  117. \fB\-\-detach\fR
  118. used, then, as a convenience, the new worktree is associated with a branch (call it
  119. \fI<branch>\fR) named after
  120. \fB$\fR(\fBbasename\fR
  121. \fI<path>\fR)\&. If
  122. \fI<branch>\fR
  123. doesn\(cqt exist, a new branch based on
  124. \fBHEAD\fR
  125. is automatically created as if
  126. \fB\-b\fR
  127. \fI<branch>\fR
  128. was given\&. If
  129. \fI<branch>\fR
  130. does exist, it will be checked out in the new worktree, if it\(cqs not checked out anywhere else, otherwise the command will refuse to create the worktree (unless
  131. \fB\-\-force\fR
  132. is used)\&.
  133. .sp
  134. If
  135. \fI<commit\-ish>\fR
  136. is omitted, neither
  137. \fB\-\-detach\fR, or
  138. \fB\-\-orphan\fR
  139. is used, and there are no valid local branches (or remote branches if
  140. \fB\-\-guess\-remote\fR
  141. is specified) then, as a convenience, the new worktree is associated with a new unborn branch named
  142. \fI<branch>\fR
  143. (after
  144. \fB$\fR(\fBbasename\fR
  145. \fI<path>\fR) if neither
  146. \fB\-b\fR
  147. or
  148. \fB\-B\fR
  149. is used) as if
  150. \fB\-\-orphan\fR
  151. was passed to the command\&. In the event the repository has a remote and
  152. \fB\-\-guess\-remote\fR
  153. is used, but no remote or local branches exist, then the command fails with a warning reminding the user to fetch from their remote first (or override by using
  154. \fB\-f/\-\-force\fR)\&.
  155. .RE
  156. .PP
  157. list
  158. .RS 4
  159. List details of each worktree\&. The main worktree is listed first, followed by each of the linked worktrees\&. The output details include whether the worktree is bare, the revision currently checked out, the branch currently checked out (or "detached HEAD" if none), "locked" if the worktree is locked, "prunable" if the worktree can be pruned by the
  160. \fBprune\fR
  161. command\&.
  162. .RE
  163. .PP
  164. lock
  165. .RS 4
  166. If a worktree is on a portable device or network share which is not always mounted, lock it to prevent its administrative files from being pruned automatically\&. This also prevents it from being moved or deleted\&. Optionally, specify a reason for the lock with
  167. \fB\-\-reason\fR\&.
  168. .RE
  169. .PP
  170. move
  171. .RS 4
  172. Move a worktree to a new location\&. Note that the main worktree or linked worktrees containing submodules cannot be moved with this command\&. (The
  173. \fBgit\fR
  174. \fBworktree\fR
  175. \fBrepair\fR
  176. command, however, can reestablish the connection with linked worktrees if you move the main worktree manually\&.)
  177. .RE
  178. .PP
  179. prune
  180. .RS 4
  181. Prune worktree information in
  182. \fB$GIT_DIR/worktrees\fR\&.
  183. .RE
  184. .PP
  185. remove
  186. .RS 4
  187. Remove a worktree\&. Only clean worktrees (no untracked files and no modification in tracked files) can be removed\&. Unclean worktrees or ones with submodules can be removed with
  188. \fB\-\-force\fR\&. The main worktree cannot be removed\&.
  189. .RE
  190. .PP
  191. repair [<path>\&...\:]
  192. .RS 4
  193. Repair worktree administrative files, if possible, if they have become corrupted or outdated due to external factors\&.
  194. .sp
  195. For instance, if the main worktree (or bare repository) is moved, linked worktrees will be unable to locate it\&. Running
  196. \fBrepair\fR
  197. in the main worktree will reestablish the connection from linked worktrees back to the main worktree\&.
  198. .sp
  199. Similarly, if the working tree for a linked worktree is moved without using
  200. \fBgit\fR
  201. \fBworktree\fR
  202. \fBmove\fR, the main worktree (or bare repository) will be unable to locate it\&. Running
  203. \fBrepair\fR
  204. within the recently\-moved worktree will reestablish the connection\&. If multiple linked worktrees are moved, running
  205. \fBrepair\fR
  206. from any worktree with each tree\(cqs new
  207. \fI<path>\fR
  208. as an argument, will reestablish the connection to all the specified paths\&.
  209. .sp
  210. If both the main worktree and linked worktrees have been moved or copied manually, then running
  211. \fBrepair\fR
  212. in the main worktree and specifying the new
  213. \fI<path>\fR
  214. of each linked worktree will reestablish all connections in both directions\&.
  215. .RE
  216. .PP
  217. unlock
  218. .RS 4
  219. Unlock a worktree, allowing it to be pruned, moved or deleted\&.
  220. .RE
  221. .SH "OPTIONS"
  222. .PP
  223. \-f, \-\-force
  224. .RS 4
  225. By default,
  226. \fBadd\fR
  227. refuses to create a new worktree when
  228. \fI<commit\-ish>\fR
  229. is a branch name and is already checked out by another worktree, or if
  230. \fI<path>\fR
  231. is already assigned to some worktree but is missing (for instance, if
  232. \fI<path>\fR
  233. was deleted manually)\&. This option overrides these safeguards\&. To add a missing but locked worktree path, specify
  234. \fB\-\-force\fR
  235. twice\&.
  236. .sp
  237. \fBmove\fR
  238. refuses to move a locked worktree unless
  239. \fB\-\-force\fR
  240. is specified twice\&. If the destination is already assigned to some other worktree but is missing (for instance, if
  241. \fI<new\-path>\fR
  242. was deleted manually), then
  243. \fB\-\-force\fR
  244. allows the move to proceed; use
  245. \fB\-\-force\fR
  246. twice if the destination is locked\&.
  247. .sp
  248. \fBremove\fR
  249. refuses to remove an unclean worktree unless
  250. \fB\-\-force\fR
  251. is used\&. To remove a locked worktree, specify
  252. \fB\-\-force\fR
  253. twice\&.
  254. .RE
  255. .PP
  256. \-b <new\-branch>, \-B <new\-branch>
  257. .RS 4
  258. With
  259. \fBadd\fR, create a new branch named
  260. \fI<new\-branch>\fR
  261. starting at
  262. \fI<commit\-ish>\fR, and check out
  263. \fI<new\-branch>\fR
  264. into the new worktree\&. If
  265. \fI<commit\-ish>\fR
  266. is omitted, it defaults to
  267. \fBHEAD\fR\&. By default,
  268. \fB\-b\fR
  269. refuses to create a new branch if it already exists\&.
  270. \fB\-B\fR
  271. overrides this safeguard, resetting
  272. \fI<new\-branch>\fR
  273. to
  274. \fI<commit\-ish>\fR\&.
  275. .RE
  276. .PP
  277. \-d, \-\-detach
  278. .RS 4
  279. With
  280. \fBadd\fR, detach
  281. \fBHEAD\fR
  282. in the new worktree\&. See "DETACHED HEAD" in
  283. \fBgit-checkout\fR(1)\&.
  284. .RE
  285. .PP
  286. \-\-[no\-]checkout
  287. .RS 4
  288. By default,
  289. \fBadd\fR
  290. checks out
  291. \fI<commit\-ish>\fR, however,
  292. \fB\-\-no\-checkout\fR
  293. can be used to suppress checkout in order to make customizations, such as configuring sparse\-checkout\&. See "Sparse checkout" in
  294. \fBgit-read-tree\fR(1)\&.
  295. .RE
  296. .PP
  297. \-\-[no\-]guess\-remote
  298. .RS 4
  299. With
  300. \fBworktree\fR
  301. \fBadd\fR
  302. \fI<path>\fR, without
  303. \fI<commit\-ish>\fR, instead of creating a new branch from
  304. \fBHEAD\fR, if there exists a tracking branch in exactly one remote matching the basename of
  305. \fI<path>\fR, base the new branch on the remote\-tracking branch, and mark the remote\-tracking branch as "upstream" from the new branch\&.
  306. .sp
  307. This can also be set up as the default behaviour by using the
  308. \fBworktree\&.guessRemote\fR
  309. config option\&.
  310. .RE
  311. .PP
  312. \-\-[no\-]relative\-paths
  313. .RS 4
  314. Link worktrees using relative paths or absolute paths (default)\&. Overrides the
  315. \fBworktree\&.useRelativePaths\fR
  316. config option, see
  317. \fBgit-config\fR(1)\&.
  318. .sp
  319. With
  320. \fBrepair\fR, the linking files will be updated if there\(cqs an absolute/relative mismatch, even if the links are correct\&.
  321. .RE
  322. .PP
  323. \-\-[no\-]track
  324. .RS 4
  325. When creating a new branch, if
  326. \fI<commit\-ish>\fR
  327. is a branch, mark it as "upstream" from the new branch\&. This is the default if
  328. \fI<commit\-ish>\fR
  329. is a remote\-tracking branch\&. See
  330. \fB\-\-track\fR
  331. in
  332. \fBgit-branch\fR(1)
  333. for details\&.
  334. .RE
  335. .PP
  336. \-\-lock
  337. .RS 4
  338. Keep the worktree locked after creation\&. This is the equivalent of
  339. \fBgit\fR
  340. \fBworktree\fR
  341. \fBlock\fR
  342. after
  343. \fBgit\fR
  344. \fBworktree\fR
  345. \fBadd\fR, but without a race condition\&.
  346. .RE
  347. .PP
  348. \-n, \-\-dry\-run
  349. .RS 4
  350. With
  351. \fBprune\fR, do not remove anything; just report what it would remove\&.
  352. .RE
  353. .PP
  354. \-\-orphan
  355. .RS 4
  356. With
  357. \fBadd\fR, make the new worktree and index empty, associating the worktree with a new unborn branch named
  358. \fI<new\-branch>\fR\&.
  359. .RE
  360. .PP
  361. \-\-porcelain
  362. .RS 4
  363. With
  364. \fBlist\fR, output in an easy\-to\-parse format for scripts\&. This format will remain stable across Git versions and regardless of user configuration\&. It is recommended to combine this with
  365. \fB\-z\fR\&. See below for details\&.
  366. .RE
  367. .PP
  368. \-z
  369. .RS 4
  370. Terminate each line with a NUL rather than a newline when
  371. \fB\-\-porcelain\fR
  372. is specified with
  373. \fBlist\fR\&. This makes it possible to parse the output when a worktree path contains a newline character\&.
  374. .RE
  375. .PP
  376. \-q, \-\-quiet
  377. .RS 4
  378. With
  379. \fBadd\fR, suppress feedback messages\&.
  380. .RE
  381. .PP
  382. \-v, \-\-verbose
  383. .RS 4
  384. With
  385. \fBprune\fR, report all removals\&.
  386. .sp
  387. With
  388. \fBlist\fR, output additional information about worktrees (see below)\&.
  389. .RE
  390. .PP
  391. \-\-expire <time>
  392. .RS 4
  393. With
  394. \fBprune\fR, only expire unused worktrees older than
  395. \fI<time>\fR\&.
  396. .sp
  397. With
  398. \fBlist\fR, annotate missing worktrees as prunable if they are older than
  399. \fI<time>\fR\&.
  400. .RE
  401. .PP
  402. \-\-reason <string>
  403. .RS 4
  404. With
  405. \fBlock\fR
  406. or with
  407. \fBadd\fR
  408. \fB\-\-lock\fR, an explanation why the worktree is locked\&.
  409. .RE
  410. .PP
  411. <worktree>
  412. .RS 4
  413. Worktrees can be identified by path, either relative or absolute\&.
  414. .sp
  415. If the last path components in the worktree\(cqs path is unique among worktrees, it can be used to identify a worktree\&. For example if you only have two worktrees, at
  416. \fB/abc/def/ghi\fR
  417. and
  418. \fB/abc/def/ggg\fR, then
  419. \fBghi\fR
  420. or
  421. \fBdef/ghi\fR
  422. is enough to point to the former worktree\&.
  423. .RE
  424. .SH "REFS"
  425. .sp
  426. When using multiple worktrees, some refs are shared between all worktrees, but others are specific to an individual worktree\&. One example is \fBHEAD\fR, which is different for each worktree\&. This section is about the sharing rules and how to access refs of one worktree from another\&.
  427. .sp
  428. In general, all pseudo refs are per\-worktree and all refs starting with \fBrefs/\fR are shared\&. Pseudo refs are ones like \fBHEAD\fR which are directly under \fB$GIT_DIR\fR instead of inside \fB$GIT_DIR/refs\fR\&. There are exceptions, however: refs inside \fBrefs/bisect\fR, \fBrefs/worktree\fR and \fBrefs/rewritten\fR are not shared\&.
  429. .sp
  430. Refs that are per\-worktree can still be accessed from another worktree via two special paths, \fBmain\-worktree\fR and \fBworktrees\fR\&. The former gives access to per\-worktree refs of the main worktree, while the latter to all linked worktrees\&.
  431. .sp
  432. For example, \fBmain\-worktree/HEAD\fR or \fBmain\-worktree/refs/bisect/good\fR resolve to the same value as the main worktree\(cqs \fBHEAD\fR and \fBrefs/bisect/good\fR respectively\&. Similarly, \fBworktrees/foo/HEAD\fR or \fBworktrees/bar/refs/bisect/bad\fR are the same as \fB$GIT_COMMON_DIR/worktrees/foo/HEAD\fR and \fB$GIT_COMMON_DIR/worktrees/bar/refs/bisect/bad\fR\&.
  433. .sp
  434. To access refs, it\(cqs best not to look inside \fB$GIT_DIR\fR directly\&. Instead use commands such as \fBgit-rev-parse\fR(1) or \fBgit-update-ref\fR(1) which will handle refs correctly\&.
  435. .SH "CONFIGURATION FILE"
  436. .sp
  437. By default, the repository \fBconfig\fR file is shared across all worktrees\&. If the config variables \fBcore\&.bare\fR or \fBcore\&.worktree\fR are present in the common config file and \fBextensions\&.worktreeConfig\fR is disabled, then they will be applied to the main worktree only\&.
  438. .sp
  439. In order to have worktree\-specific configuration, you can turn on the \fBworktreeConfig\fR extension, e\&.g\&.:
  440. .sp
  441. .if n \{\
  442. .RS 4
  443. .\}
  444. .nf
  445. $ git config extensions\&.worktreeConfig true
  446. .fi
  447. .if n \{\
  448. .RE
  449. .\}
  450. .sp
  451. In this mode, specific configuration stays in the path pointed by \fBgit\fR \fBrev\-parse\fR \fB\-\-git\-path\fR \fBconfig\&.worktree\fR\&. You can add or update configuration in this file with \fBgit\fR \fBconfig\fR \fB\-\-worktree\fR\&. Older Git versions will refuse to access repositories with this extension\&.
  452. .sp
  453. Note that in this file, the exception for \fBcore\&.bare\fR and \fBcore\&.worktree\fR is gone\&. If they exist in \fB$GIT_DIR/config\fR, you must move them to the \fBconfig\&.worktree\fR of the main worktree\&. You may also take this opportunity to review and move other configuration that you do not want to share to all worktrees:
  454. .sp
  455. .RS 4
  456. .ie n \{\
  457. \h'-04'\(bu\h'+03'\c
  458. .\}
  459. .el \{\
  460. .sp -1
  461. .IP \(bu 2.3
  462. .\}
  463. \fBcore\&.worktree\fR
  464. should never be shared\&.
  465. .RE
  466. .sp
  467. .RS 4
  468. .ie n \{\
  469. \h'-04'\(bu\h'+03'\c
  470. .\}
  471. .el \{\
  472. .sp -1
  473. .IP \(bu 2.3
  474. .\}
  475. \fBcore\&.bare\fR
  476. should not be shared if the value is
  477. \fBcore\&.bare=true\fR\&.
  478. .RE
  479. .sp
  480. .RS 4
  481. .ie n \{\
  482. \h'-04'\(bu\h'+03'\c
  483. .\}
  484. .el \{\
  485. .sp -1
  486. .IP \(bu 2.3
  487. .\}
  488. \fBcore\&.sparseCheckout\fR
  489. should not be shared, unless you are sure you always use sparse checkout for all worktrees\&.
  490. .RE
  491. .sp
  492. See the documentation of \fBextensions\&.worktreeConfig\fR in \fBgit-config\fR(1) for more details\&.
  493. .SH "DETAILS"
  494. .sp
  495. Each linked worktree has a private sub\-directory in the repository\(cqs \fB$GIT_DIR/worktrees\fR directory\&. The private sub\-directory\(cqs name is usually the base name of the linked worktree\(cqs path, possibly appended with a number to make it unique\&. For example, when \fB$GIT_DIR=/path/main/\&.git\fR the command \fBgit\fR \fBworktree\fR \fBadd\fR \fB/path/other/test\-next\fR \fBnext\fR creates the linked worktree in \fB/path/other/test\-next\fR and also creates a \fB$GIT_DIR/worktrees/test\-next\fR directory (or \fB$GIT_DIR/worktrees/test\-next1\fR if \fBtest\-next\fR is already taken)\&.
  496. .sp
  497. Within a linked worktree, \fB$GIT_DIR\fR is set to point to this private directory (e\&.g\&. \fB/path/main/\&.git/worktrees/test\-next\fR in the example) and \fB$GIT_COMMON_DIR\fR is set to point back to the main worktree\(cqs \fB$GIT_DIR\fR (e\&.g\&. \fB/path/main/\&.git\fR)\&. These settings are made in a \&.\fBgit\fR file located at the top directory of the linked worktree\&.
  498. .sp
  499. Path resolution via \fBgit\fR \fBrev\-parse\fR \fB\-\-git\-path\fR uses either \fB$GIT_DIR\fR or \fB$GIT_COMMON_DIR\fR depending on the path\&. For example, in the linked worktree \fBgit\fR \fBrev\-parse\fR \fB\-\-git\-path\fR \fBHEAD\fR returns \fB/path/main/\&.git/worktrees/test\-next/HEAD\fR (not \fB/path/other/test\-next/\&.git/HEAD\fR or \fB/path/main/\&.git/HEAD\fR) while \fBgit\fR \fBrev\-parse\fR \fB\-\-git\-path\fR \fBrefs/heads/master\fR uses \fB$GIT_COMMON_DIR\fR and returns \fB/path/main/\&.git/refs/heads/master\fR, since refs are shared across all worktrees, except \fBrefs/bisect\fR, \fBrefs/worktree\fR and \fBrefs/rewritten\fR\&.
  500. .sp
  501. See \fBgitrepository-layout\fR(5) for more information\&. The rule of thumb is do not make any assumption about whether a path belongs to \fB$GIT_DIR\fR or \fB$GIT_COMMON_DIR\fR when you need to directly access something inside \fB$GIT_DIR\fR\&. Use \fBgit\fR \fBrev\-parse\fR \fB\-\-git\-path\fR to get the final path\&.
  502. .sp
  503. If you manually move a linked worktree, you need to update the \fBgitdir\fR file in the entry\(cqs directory\&. For example, if a linked worktree is moved to \fB/newpath/test\-next\fR and its \&.\fBgit\fR file points to \fB/path/main/\&.git/worktrees/test\-next\fR, then update \fB/path/main/\&.git/worktrees/test\-next/gitdir\fR to reference \fB/newpath/test\-next\fR instead\&. Better yet, run \fBgit\fR \fBworktree\fR \fBrepair\fR to reestablish the connection automatically\&.
  504. .sp
  505. To prevent a \fB$GIT_DIR/worktrees\fR entry from being pruned (which can be useful in some situations, such as when the entry\(cqs worktree is stored on a portable device), use the \fBgit\fR \fBworktree\fR \fBlock\fR command, which adds a file named \fBlocked\fR to the entry\(cqs directory\&. The file contains the reason in plain text\&. For example, if a linked worktree\(cqs \&.\fBgit\fR file points to \fB/path/main/\&.git/worktrees/test\-next\fR then a file named \fB/path/main/\&.git/worktrees/test\-next/locked\fR will prevent the \fBtest\-next\fR entry from being pruned\&. See \fBgitrepository-layout\fR(5) for details\&.
  506. .sp
  507. When \fBextensions\&.worktreeConfig\fR is enabled, the config file \&.\fBgit/worktrees/\fR\fI<id>\fR\fB/config\&.worktree\fR is read after \&.\fBgit/config\fR is\&.
  508. .SH "LIST OUTPUT FORMAT"
  509. .sp
  510. The \fBworktree\fR \fBlist\fR command has two output formats\&. The default format shows the details on a single line with columns\&. For example:
  511. .sp
  512. .if n \{\
  513. .RS 4
  514. .\}
  515. .nf
  516. $ git worktree list
  517. /path/to/bare\-source (bare)
  518. /path/to/linked\-worktree abcd1234 [master]
  519. /path/to/other\-linked\-worktree 1234abc (detached HEAD)
  520. .fi
  521. .if n \{\
  522. .RE
  523. .\}
  524. .sp
  525. The command also shows annotations for each worktree, according to its state\&. These annotations are:
  526. .sp
  527. .RS 4
  528. .ie n \{\
  529. \h'-04'\(bu\h'+03'\c
  530. .\}
  531. .el \{\
  532. .sp -1
  533. .IP \(bu 2.3
  534. .\}
  535. \fBlocked\fR, if the worktree is locked\&.
  536. .RE
  537. .sp
  538. .RS 4
  539. .ie n \{\
  540. \h'-04'\(bu\h'+03'\c
  541. .\}
  542. .el \{\
  543. .sp -1
  544. .IP \(bu 2.3
  545. .\}
  546. \fBprunable\fR, if the worktree can be pruned via
  547. \fBgit\fR
  548. \fBworktree\fR
  549. \fBprune\fR\&.
  550. .RE
  551. .sp
  552. .if n \{\
  553. .RS 4
  554. .\}
  555. .nf
  556. $ git worktree list
  557. /path/to/linked\-worktree abcd1234 [master]
  558. /path/to/locked\-worktree acbd5678 (brancha) locked
  559. /path/to/prunable\-worktree 5678abc (detached HEAD) prunable
  560. .fi
  561. .if n \{\
  562. .RE
  563. .\}
  564. .sp
  565. For these annotations, a reason might also be available and this can be seen using the verbose mode\&. The annotation is then moved to the next line indented followed by the additional information\&.
  566. .sp
  567. .if n \{\
  568. .RS 4
  569. .\}
  570. .nf
  571. $ git worktree list \-\-verbose
  572. /path/to/linked\-worktree abcd1234 [master]
  573. /path/to/locked\-worktree\-no\-reason abcd5678 (detached HEAD) locked
  574. /path/to/locked\-worktree\-with\-reason 1234abcd (brancha)
  575. locked: worktree path is mounted on a portable device
  576. /path/to/prunable\-worktree 5678abc1 (detached HEAD)
  577. prunable: gitdir file points to non\-existent location
  578. .fi
  579. .if n \{\
  580. .RE
  581. .\}
  582. .sp
  583. Note that the annotation is moved to the next line if the additional information is available, otherwise it stays on the same line as the worktree itself\&.
  584. .SS "Porcelain Format"
  585. .sp
  586. The porcelain format has a line per attribute\&. If \fB\-z\fR is given then the lines are terminated with NUL rather than a newline\&. Attributes are listed with a label and value separated by a single space\&. Boolean attributes (like \fBbare\fR and \fBdetached\fR) are listed as a label only, and are present only if the value is true\&. Some attributes (like \fBlocked\fR) can be listed as a label only or with a value depending upon whether a reason is available\&. The first attribute of a worktree is always \fBworktree\fR, an empty line indicates the end of the record\&. For example:
  587. .sp
  588. .if n \{\
  589. .RS 4
  590. .\}
  591. .nf
  592. $ git worktree list \-\-porcelain
  593. worktree /path/to/bare\-source
  594. bare
  595. worktree /path/to/linked\-worktree
  596. HEAD abcd1234abcd1234abcd1234abcd1234abcd1234
  597. branch refs/heads/master
  598. worktree /path/to/other\-linked\-worktree
  599. HEAD 1234abc1234abc1234abc1234abc1234abc1234a
  600. detached
  601. worktree /path/to/linked\-worktree\-locked\-no\-reason
  602. HEAD 5678abc5678abc5678abc5678abc5678abc5678c
  603. branch refs/heads/locked\-no\-reason
  604. locked
  605. worktree /path/to/linked\-worktree\-locked\-with\-reason
  606. HEAD 3456def3456def3456def3456def3456def3456b
  607. branch refs/heads/locked\-with\-reason
  608. locked reason why is locked
  609. worktree /path/to/linked\-worktree\-prunable
  610. HEAD 1233def1234def1234def1234def1234def1234b
  611. detached
  612. prunable gitdir file points to non\-existent location
  613. .fi
  614. .if n \{\
  615. .RE
  616. .\}
  617. .sp
  618. Unless \fB\-z\fR is used any "unusual" characters in the lock reason such as newlines are escaped and the entire reason is quoted as explained for the configuration variable \fBcore\&.quotePath\fR (see \fBgit-config\fR(1))\&. For Example:
  619. .sp
  620. .if n \{\
  621. .RS 4
  622. .\}
  623. .nf
  624. $ git worktree list \-\-porcelain
  625. \&.\&.\&.
  626. locked "reason\enwhy is locked"
  627. \&.\&.\&.
  628. .fi
  629. .if n \{\
  630. .RE
  631. .\}
  632. .SH "EXAMPLES"
  633. .sp
  634. You are in the middle of a refactoring session and your boss comes in and demands that you fix something immediately\&. You might typically use \fBgit-stash\fR(1) to store your changes away temporarily, however, your working tree is in such a state of disarray (with new, moved, and removed files, and other bits and pieces strewn around) that you don\(cqt want to risk disturbing any of it\&. Instead, you create a temporary linked worktree to make the emergency fix, remove it when done, and then resume your earlier refactoring session\&.
  635. .sp
  636. .if n \{\
  637. .RS 4
  638. .\}
  639. .nf
  640. $ git worktree add \-b emergency\-fix \&.\&./temp master
  641. $ pushd \&.\&./temp
  642. # \&.\&.\&. hack hack hack \&.\&.\&.
  643. $ git commit \-a \-m \*(Aqemergency fix for boss\*(Aq
  644. $ popd
  645. $ git worktree remove \&.\&./temp
  646. .fi
  647. .if n \{\
  648. .RE
  649. .\}
  650. .SH "BUGS"
  651. .sp
  652. Multiple checkout in general is still experimental, and the support for submodules is incomplete\&. It is NOT recommended to make multiple checkouts of a superproject\&.
  653. .SH "GIT"
  654. .sp
  655. Part of the \fBgit\fR(1) suite