doc: convert git worktree to synopsis style

- Switch the synopsis to a synopsis block which will automatically
  format placeholders in italics and keywords in monospace
- Use _<placeholder>_ instead of <placeholder> in the description
- Use `backticks` for keywords and more complex option
descriptions. The new rendering engine will apply synopsis rules to
these spans.

Also add the config section in the manual page and do not refer to the man
page in the description of settings when this description is already in the
man page.

Signed-off-by: Jean-Noël Avila <jn.avila@free.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
main
Jean-Noël Avila 2025-10-05 21:11:42 +00:00 committed by Junio C Hamano
parent 0fc3a21a9e
commit 0ae23ab57f
2 changed files with 91 additions and 84 deletions

View File

@ -1,4 +1,4 @@
worktree.guessRemote:: `worktree.guessRemote`::
If no branch is specified and neither `-b` nor `-B` nor If no branch is specified and neither `-b` nor `-B` nor
`--detach` is used, then `git worktree add` defaults to `--detach` is used, then `git worktree add` defaults to
creating a new branch from HEAD. If `worktree.guessRemote` is creating a new branch from HEAD. If `worktree.guessRemote` is
@ -6,14 +6,14 @@ worktree.guessRemote::
branch whose name uniquely matches the new branch name. If branch whose name uniquely matches the new branch name. If
such a branch exists, it is checked out and set as "upstream" such a branch exists, it is checked out and set as "upstream"
for the new branch. If no such match can be found, it falls for the new branch. If no such match can be found, it falls
back to creating a new branch from the current HEAD. back to creating a new branch from the current `HEAD`.


worktree.useRelativePaths:: `worktree.useRelativePaths`::
Link worktrees using relative paths (when "true") or absolute Link worktrees using relative paths (when "`true`") or absolute
paths (when "false"). This is particularly useful for setups paths (when "`false`"). This is particularly useful for setups
where the repository and worktrees may be moved between where the repository and worktrees may be moved between
different locations or environments. Defaults to "false". different locations or environments. Defaults to "`false`".
+ +
Note that setting `worktree.useRelativePaths` to "true" implies enabling the Note that setting `worktree.useRelativePaths` to "`true`" implies enabling the
`extensions.relativeWorktrees` config (see linkgit:git-config[1]), `extensions.relativeWorktrees` config (see linkgit:git-config[1]),
thus making it incompatible with older versions of Git. thus making it incompatible with older versions of Git.

View File

@ -8,16 +8,16 @@ git-worktree - Manage multiple working trees


SYNOPSIS SYNOPSIS
-------- --------
[verse] [synopsis]
'git worktree add' [-f] [--detach] [--checkout] [--lock [--reason <string>]] git worktree add [-f] [--detach] [--checkout] [--lock [--reason <string>]]
[--orphan] [(-b | -B) <new-branch>] <path> [<commit-ish>] [--orphan] [(-b | -B) <new-branch>] <path> [<commit-ish>]
'git worktree list' [-v | --porcelain [-z]] git worktree list [-v | --porcelain [-z]]
'git worktree lock' [--reason <string>] <worktree> git worktree lock [--reason <string>] <worktree>
'git worktree move' <worktree> <new-path> git worktree move <worktree> <new-path>
'git worktree prune' [-n] [-v] [--expire <expire>] git worktree prune [-n] [-v] [--expire <expire>]
'git worktree remove' [-f] <worktree> git worktree remove [-f] <worktree>
'git worktree repair' [<path>...] git worktree repair [<path>...]
'git worktree unlock' <worktree> git worktree unlock <worktree>


DESCRIPTION DESCRIPTION
----------- -----------
@ -37,7 +37,7 @@ zero or more linked worktrees. When you are done with a linked worktree,
remove it with `git worktree remove`. remove it with `git worktree remove`.


In its simplest form, `git worktree add <path>` automatically creates a In its simplest form, `git worktree add <path>` automatically creates a
new branch whose name is the final component of `<path>`, which is new branch whose name is the final component of _<path>_, which is
convenient if you plan to work on a new topic. For instance, `git convenient if you plan to work on a new topic. For instance, `git
worktree add ../hotfix` creates new branch `hotfix` and checks it out at worktree add ../hotfix` creates new branch `hotfix` and checks it out at
path `../hotfix`. To instead work on an existing branch in a new worktree, path `../hotfix`. To instead work on an existing branch in a new worktree,
@ -63,16 +63,16 @@ locked.


COMMANDS COMMANDS
-------- --------
add <path> [<commit-ish>]:: `add <path> [<commit-ish>]`::


Create a worktree at `<path>` and checkout `<commit-ish>` into it. The new worktree Create a worktree at _<path>_ and checkout _<commit-ish>_ into it. The new worktree
is linked to the current repository, sharing everything except per-worktree is linked to the current repository, sharing everything except per-worktree
files such as `HEAD`, `index`, etc. As a convenience, `<commit-ish>` may files such as `HEAD`, `index`, etc. As a convenience, _<commit-ish>_ may
be a bare "`-`", which is synonymous with `@{-1}`. be a bare "`-`", which is synonymous with `@{-1}`.
+ +
If `<commit-ish>` is a branch name (call it `<branch>`) and is not found, If _<commit-ish>_ is a branch name (call it _<branch>_) and is not found,
and neither `-b` nor `-B` nor `--detach` are used, but there does and neither `-b` nor `-B` nor `--detach` are used, but there does
exist a tracking branch in exactly one remote (call it `<remote>`) exist a tracking branch in exactly one remote (call it _<remote>_)
with a matching name, treat as equivalent to: with a matching name, treat as equivalent to:
+ +
------------ ------------
@ -81,32 +81,32 @@ $ git worktree add --track -b <branch> <path> <remote>/<branch>
+ +
If the branch exists in multiple remotes and one of them is named by If the branch exists in multiple remotes and one of them is named by
the `checkout.defaultRemote` configuration variable, we'll use that the `checkout.defaultRemote` configuration variable, we'll use that
one for the purposes of disambiguation, even if the `<branch>` isn't one for the purposes of disambiguation, even if the _<branch>_ isn't
unique across all remotes. Set it to unique across all remotes. Set it to
e.g. `checkout.defaultRemote=origin` to always checkout remote e.g. `checkout.defaultRemote=origin` to always checkout remote
branches from there if `<branch>` is ambiguous but exists on the branches from there if _<branch>_ is ambiguous but exists on the
`origin` remote. See also `checkout.defaultRemote` in `origin` remote. See also `checkout.defaultRemote` in
linkgit:git-config[1]. linkgit:git-config[1].
+ +
If `<commit-ish>` is omitted and neither `-b` nor `-B` nor `--detach` used, If _<commit-ish>_ is omitted and neither `-b` nor `-B` nor `--detach` used,
then, as a convenience, the new worktree is associated with a branch (call then, as a convenience, the new worktree is associated with a branch (call
it `<branch>`) named after `$(basename <path>)`. If `<branch>` doesn't it _<branch>_) named after `$(basename <path>)`. If _<branch>_ doesn't
exist, a new branch based on `HEAD` is automatically created as if exist, a new branch based on `HEAD` is automatically created as if
`-b <branch>` was given. If `<branch>` does exist, it will be checked out `-b <branch>` was given. If _<branch>_ does exist, it will be checked out
in the new worktree, if it's not checked out anywhere else, otherwise the in the new worktree, if it's not checked out anywhere else, otherwise the
command will refuse to create the worktree (unless `--force` is used). command will refuse to create the worktree (unless `--force` is used).
+ +
If `<commit-ish>` is omitted, neither `--detach`, or `--orphan` is If _<commit-ish>_ is omitted, neither `--detach`, or `--orphan` is
used, and there are no valid local branches (or remote branches if used, and there are no valid local branches (or remote branches if
`--guess-remote` is specified) then, as a convenience, the new worktree is `--guess-remote` is specified) then, as a convenience, the new worktree is
associated with a new unborn branch named `<branch>` (after associated with a new unborn branch named _<branch>_ (after
`$(basename <path>)` if neither `-b` or `-B` is used) as if `--orphan` was `$(basename <path>)` if neither `-b` or `-B` is used) as if `--orphan` was
passed to the command. In the event the repository has a remote and passed to the command. In the event the repository has a remote and
`--guess-remote` is used, but no remote or local branches exist, then the `--guess-remote` is used, but no remote or local branches exist, then the
command fails with a warning reminding the user to fetch from their remote command fails with a warning reminding the user to fetch from their remote
first (or override by using `-f/--force`). first (or override by using `-f/--force`).


list:: `list`::


List details of each worktree. The main worktree is listed first, List details of each worktree. The main worktree is listed first,
followed by each of the linked worktrees. The output details include followed by each of the linked worktrees. The output details include
@ -115,32 +115,32 @@ branch currently checked out (or "detached HEAD" if none), "locked" if
the worktree is locked, "prunable" if the worktree can be pruned by the the worktree is locked, "prunable" if the worktree can be pruned by the
`prune` command. `prune` command.


lock:: `lock`::


If a worktree is on a portable device or network share which is not always 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 mounted, lock it to prevent its administrative files from being pruned
automatically. This also prevents it from being moved or deleted. automatically. This also prevents it from being moved or deleted.
Optionally, specify a reason for the lock with `--reason`. Optionally, specify a reason for the lock with `--reason`.


move:: `move`::


Move a worktree to a new location. Note that the main worktree or linked Move a worktree to a new location. Note that the main worktree or linked
worktrees containing submodules cannot be moved with this command. (The worktrees containing submodules cannot be moved with this command. (The
`git worktree repair` command, however, can reestablish the connection `git worktree repair` command, however, can reestablish the connection
with linked worktrees if you move the main worktree manually.) with linked worktrees if you move the main worktree manually.)


prune:: `prune`::


Prune worktree information in `$GIT_DIR/worktrees`. Prune worktree information in `$GIT_DIR/worktrees`.


remove:: `remove`::


Remove a worktree. Only clean worktrees (no untracked files and no Remove a worktree. Only clean worktrees (no untracked files and no
modification in tracked files) can be removed. Unclean worktrees or ones modification in tracked files) can be removed. Unclean worktrees or ones
with submodules can be removed with `--force`. The main worktree cannot be with submodules can be removed with `--force`. The main worktree cannot be
removed. removed.


repair [<path>...]:: `repair [<path>...]`::


Repair worktree administrative files, if possible, if they have become Repair worktree administrative files, if possible, if they have become
corrupted or outdated due to external factors. corrupted or outdated due to external factors.
@ -154,72 +154,72 @@ Similarly, if the working tree for a linked worktree is moved without
using `git worktree move`, the main worktree (or bare repository) will be using `git worktree move`, the main worktree (or bare repository) will be
unable to locate it. Running `repair` within the recently-moved worktree unable to locate it. Running `repair` within the recently-moved worktree
will reestablish the connection. If multiple linked worktrees are moved, will reestablish the connection. If multiple linked worktrees are moved,
running `repair` from any worktree with each tree's new `<path>` as an running `repair` from any worktree with each tree's new _<path>_ as an
argument, will reestablish the connection to all the specified paths. argument, will reestablish the connection to all the specified paths.
+ +
If both the main worktree and linked worktrees have been moved or copied manually, If both the main worktree and linked worktrees have been moved or copied manually,
then running `repair` in the main worktree and specifying the new `<path>` then running `repair` in the main worktree and specifying the new _<path>_
of each linked worktree will reestablish all connections in both of each linked worktree will reestablish all connections in both
directions. directions.


unlock:: `unlock`::


Unlock a worktree, allowing it to be pruned, moved or deleted. Unlock a worktree, allowing it to be pruned, moved or deleted.


OPTIONS OPTIONS
------- -------


-f:: `-f`::
--force:: `--force`::
By default, `add` refuses to create a new worktree when By default, `add` refuses to create a new worktree when
`<commit-ish>` is a branch name and is already checked out by _<commit-ish>_ is a branch name and is already checked out by
another worktree, or if `<path>` is already assigned to some another worktree, or if _<path>_ is already assigned to some
worktree but is missing (for instance, if `<path>` was deleted worktree but is missing (for instance, if _<path>_ was deleted
manually). This option overrides these safeguards. To add a missing but manually). This option overrides these safeguards. To add a missing but
locked worktree path, specify `--force` twice. locked worktree path, specify `--force` twice.
+ +
`move` refuses to move a locked worktree unless `--force` is specified `move` refuses to move a locked worktree unless `--force` is specified
twice. If the destination is already assigned to some other worktree but is twice. If the destination is already assigned to some other worktree but is
missing (for instance, if `<new-path>` was deleted manually), then `--force` missing (for instance, if _<new-path>_ was deleted manually), then `--force`
allows the move to proceed; use `--force` twice if the destination is locked. allows the move to proceed; use `--force` twice if the destination is locked.
+ +
`remove` refuses to remove an unclean worktree unless `--force` is used. `remove` refuses to remove an unclean worktree unless `--force` is used.
To remove a locked worktree, specify `--force` twice. To remove a locked worktree, specify `--force` twice.


-b <new-branch>:: `-b <new-branch>`::
-B <new-branch>:: `-B <new-branch>`::
With `add`, create a new branch named `<new-branch>` starting at With `add`, create a new branch named _<new-branch>_ starting at
`<commit-ish>`, and check out `<new-branch>` into the new worktree. _<commit-ish>_, and check out _<new-branch>_ into the new worktree.
If `<commit-ish>` is omitted, it defaults to `HEAD`. If _<commit-ish>_ is omitted, it defaults to `HEAD`.
By default, `-b` refuses to create a new branch if it already By default, `-b` refuses to create a new branch if it already
exists. `-B` overrides this safeguard, resetting `<new-branch>` to exists. `-B` overrides this safeguard, resetting _<new-branch>_ to
`<commit-ish>`. _<commit-ish>_.


-d:: `-d`::
--detach:: `--detach`::
With `add`, detach `HEAD` in the new worktree. See "DETACHED HEAD" With `add`, detach `HEAD` in the new worktree. See "DETACHED HEAD"
in linkgit:git-checkout[1]. in linkgit:git-checkout[1].


--checkout:: `--checkout`::
--no-checkout:: `--no-checkout`::
By default, `add` checks out `<commit-ish>`, however, `--no-checkout` can By default, `add` checks out _<commit-ish>_, however, `--no-checkout` can
be used to suppress checkout in order to make customizations, be used to suppress checkout in order to make customizations,
such as configuring sparse-checkout. See "Sparse checkout" such as configuring sparse-checkout. See "Sparse checkout"
in linkgit:git-read-tree[1]. in linkgit:git-read-tree[1].


--guess-remote:: `--guess-remote`::
--no-guess-remote:: `--no-guess-remote`::
With `worktree add <path>`, without `<commit-ish>`, instead With `worktree add <path>`, without _<commit-ish>_, instead
of creating a new branch from `HEAD`, if there exists a tracking of creating a new branch from `HEAD`, if there exists a tracking
branch in exactly one remote matching the basename of `<path>`, branch in exactly one remote matching the basename of _<path>_,
base the new branch on the remote-tracking branch, and mark base the new branch on the remote-tracking branch, and mark
the remote-tracking branch as "upstream" from the new branch. the remote-tracking branch as "upstream" from the new branch.
+ +
This can also be set up as the default behaviour by using the This can also be set up as the default behaviour by using the
`worktree.guessRemote` config option. `worktree.guessRemote` config option.


--relative-paths:: `--relative-paths`::
--no-relative-paths:: `--no-relative-paths`::
Link worktrees using relative paths or absolute paths (default). Link worktrees using relative paths or absolute paths (default).
Overrides the `worktree.useRelativePaths` config option, see Overrides the `worktree.useRelativePaths` config option, see
linkgit:git-config[1]. linkgit:git-config[1].
@ -227,60 +227,60 @@ This can also be set up as the default behaviour by using the
With `repair`, the linking files will be updated if there's an absolute/relative With `repair`, the linking files will be updated if there's an absolute/relative
mismatch, even if the links are correct. mismatch, even if the links are correct.


--track:: `--track`::
--no-track:: `--no-track`::
When creating a new branch, if `<commit-ish>` is a branch, When creating a new branch, if _<commit-ish>_ is a branch,
mark it as "upstream" from the new branch. This is the mark it as "upstream" from the new branch. This is the
default if `<commit-ish>` is a remote-tracking branch. See default if _<commit-ish>_ is a remote-tracking branch. See
`--track` in linkgit:git-branch[1] for details. `--track` in linkgit:git-branch[1] for details.


--lock:: `--lock`::
Keep the worktree locked after creation. This is the Keep the worktree locked after creation. This is the
equivalent of `git worktree lock` after `git worktree add`, equivalent of `git worktree lock` after `git worktree add`,
but without a race condition. but without a race condition.


-n:: `-n`::
--dry-run:: `--dry-run`::
With `prune`, do not remove anything; just report what it would With `prune`, do not remove anything; just report what it would
remove. remove.


--orphan:: `--orphan`::
With `add`, make the new worktree and index empty, associating With `add`, make the new worktree and index empty, associating
the worktree with a new unborn branch named `<new-branch>`. the worktree with a new unborn branch named _<new-branch>_.


--porcelain:: `--porcelain`::
With `list`, output in an easy-to-parse format for scripts. With `list`, output in an easy-to-parse format for scripts.
This format will remain stable across Git versions and regardless of user This format will remain stable across Git versions and regardless of user
configuration. It is recommended to combine this with `-z`. configuration. It is recommended to combine this with `-z`.
See below for details. See below for details.


-z:: `-z`::
Terminate each line with a NUL rather than a newline when Terminate each line with a _NUL_ rather than a newline when
`--porcelain` is specified with `list`. This makes it possible `--porcelain` is specified with `list`. This makes it possible
to parse the output when a worktree path contains a newline to parse the output when a worktree path contains a newline
character. character.


-q:: `-q`::
--quiet:: `--quiet`::
With `add`, suppress feedback messages. With `add`, suppress feedback messages.


-v:: `-v`::
--verbose:: `--verbose`::
With `prune`, report all removals. With `prune`, report all removals.
+ +
With `list`, output additional information about worktrees (see below). With `list`, output additional information about worktrees (see below).


--expire <time>:: `--expire <time>`::
With `prune`, only expire unused worktrees older than `<time>`. With `prune`, only expire unused worktrees older than _<time>_.
+ +
With `list`, annotate missing worktrees as prunable if they are older than With `list`, annotate missing worktrees as prunable if they are older than
`<time>`. _<time>_.


--reason <string>:: `--reason <string>`::
With `lock` or with `add --lock`, an explanation why the worktree With `lock` or with `add --lock`, an explanation why the worktree
is locked. is locked.


<worktree>:: _<worktree>_::
Worktrees can be identified by path, either relative or absolute. Worktrees can be identified by path, either relative or absolute.
+ +
If the last path components in the worktree's path is unique among If the last path components in the worktree's path is unique among
@ -522,6 +522,13 @@ $ popd
$ git worktree remove ../temp $ git worktree remove ../temp
------------ ------------


CONFIGURATION
-------------

include::includes/cmd-config-section-all.adoc[]

include::config/worktree.adoc[]

BUGS BUGS
---- ----
Multiple checkout in general is still experimental, and the support Multiple checkout in general is still experimental, and the support