Skip to content

Commit c4738ae

Browse files
tgummerergitster
authored andcommitted
worktree: add can be created from any commit-ish
Currently 'git worktree add' is documented to take an optional <branch> argument, which is checked out in the new worktree. However it is more generally possible to use a commit-ish as the optional argument, and check that out into the new worktree. Document that this is a possibility, as new users of git worktree add might find it helpful. Reported-by: Randall S. Becker <[email protected]> Signed-off-by: Thomas Gummerer <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7c85a87 commit c4738ae

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

Documentation/git-worktree.txt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ git-worktree - Manage multiple working trees
99
SYNOPSIS
1010
--------
1111
[verse]
12-
'git worktree add' [-f] [--detach] [--checkout] [--lock] [-b <new-branch>] <path> [<branch>]
12+
'git worktree add' [-f] [--detach] [--checkout] [--lock] [-b <new-branch>] <path> [<commit-ish>]
1313
'git worktree list' [--porcelain]
1414
'git worktree lock' [--reason <string>] <worktree>
1515
'git worktree prune' [-n] [-v] [--expire <expire>]
@@ -45,14 +45,14 @@ specifying `--reason` to explain why the working tree is locked.
4545

4646
COMMANDS
4747
--------
48-
add <path> [<branch>]::
48+
add <path> [<commit-ish>]::
4949

50-
Create `<path>` and checkout `<branch>` into it. The new working directory
50+
Create `<path>` and checkout `<commit-ish>` into it. The new working directory
5151
is linked to the current repository, sharing everything except working
5252
directory specific files such as HEAD, index, etc. `-` may also be
53-
specified as `<branch>`; it is synonymous with `@{-1}`.
53+
specified as `<commit-ish>`; it is synonymous with `@{-1}`.
5454
+
55-
If `<branch>` is omitted and neither `-b` nor `-B` nor `--detach` used,
55+
If `<commit-ish>` is omitted and neither `-b` nor `-B` nor `--detach` used,
5656
then, as a convenience, a new branch based at HEAD is created automatically,
5757
as if `-b $(basename <path>)` was specified.
5858

@@ -84,25 +84,25 @@ OPTIONS
8484

8585
-f::
8686
--force::
87-
By default, `add` refuses to create a new working tree when `<branch>`
87+
By default, `add` refuses to create a new working tree when `<commit-ish>` is a branch name and
8888
is already checked out by another working tree. This option overrides
8989
that safeguard.
9090

9191
-b <new-branch>::
9292
-B <new-branch>::
9393
With `add`, create a new branch named `<new-branch>` starting at
94-
`<branch>`, and check out `<new-branch>` into the new working tree.
95-
If `<branch>` is omitted, it defaults to HEAD.
94+
`<commit-ish>`, and check out `<new-branch>` into the new working tree.
95+
If `<commit-ish>` is omitted, it defaults to HEAD.
9696
By default, `-b` refuses to create a new branch if it already
9797
exists. `-B` overrides this safeguard, resetting `<new-branch>` to
98-
`<branch>`.
98+
`<commit-ish>`.
9999

100100
--detach::
101101
With `add`, detach HEAD in the new working tree. See "DETACHED HEAD"
102102
in linkgit:git-checkout[1].
103103

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

0 commit comments

Comments
 (0)