@@ -9,7 +9,7 @@ git-worktree - Manage multiple working trees
99SYNOPSIS
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,22 @@ specifying `--reason` to explain why the working tree is locked.
4545
4646COMMANDS
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
5151is linked to the current repository, sharing everything except working
5252directory 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 a branch name (call it `<branch>` and is not found,
56+ and neither `-b` nor `-B` nor `--detach` are used, but there does
57+ exist a tracking branch in exactly one remote (call it `<remote>`)
58+ with a matching name, treat as equivalent to
59+ ------------
60+ $ git worktree add --track -b <branch> <path> <remote>/<branch>
61+ ------------
62+ +
63+ If `<commit-ish>` is omitted and neither `-b` nor `-B` nor `--detach` used,
5664then, as a convenience, a new branch based at HEAD is created automatically,
5765as if `-b $(basename <path>)` was specified.
5866
@@ -84,29 +92,45 @@ OPTIONS
8492
8593-f::
8694--force::
87- By default, `add` refuses to create a new working tree when `<branch>`
95+ By default, `add` refuses to create a new working tree when `<commit-ish>` is a branch name and
8896 is already checked out by another working tree. This option overrides
8997 that safeguard.
9098
9199-b <new-branch>::
92100-B <new-branch>::
93101 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.
102+ `<commit-ish >`, and check out `<new-branch>` into the new working tree.
103+ If `<commit-ish >` is omitted, it defaults to HEAD.
96104 By default, `-b` refuses to create a new branch if it already
97105 exists. `-B` overrides this safeguard, resetting `<new-branch>` to
98- `<branch >`.
106+ `<commit-ish >`.
99107
100108--detach::
101109 With `add`, detach HEAD in the new working tree. See "DETACHED HEAD"
102110 in linkgit:git-checkout[1].
103111
104112--[no-]checkout::
105- By default, `add` checks out `<branch >`, however, `--no-checkout` can
113+ By default, `add` checks out `<commit-ish >`, however, `--no-checkout` can
106114 be used to suppress checkout in order to make customizations,
107115 such as configuring sparse-checkout. See "Sparse checkout"
108116 in linkgit:git-read-tree[1].
109117
118+ --[no-]guess-remote::
119+ With `worktree add <path>`, without `<commit-ish>`, instead
120+ of creating a new branch from HEAD, if there exists a tracking
121+ branch in exactly one remote matching the basename of `<path>,
122+ base the new branch on the remote-tracking branch, and mark
123+ the remote-tracking branch as "upstream" from the new branch.
124+ +
125+ This can also be set up as the default behaviour by using the
126+ `worktree.guessRemote` config option.
127+
128+ --[no-]track::
129+ When creating a new branch, if `<commit-ish>` is a branch,
130+ mark it as "upstream" from the new branch. This is the
131+ default if `<commit-ish>` is a remote-tracking branch. See
132+ "--track" in linkgit:git-branch[1] for details.
133+
110134--lock::
111135 Keep the working tree locked after creation. This is the
112136 equivalent of `git worktree lock` after `git worktree add`,
0 commit comments