Skip to content

Commit 45f462b

Browse files
committed
Merge branch 'es/wt-add-detach'
"git worktree add" learns that the "-d" is a synonym to "--detach" option to create a new worktree without being on a branch. * es/wt-add-detach: git-worktree.txt: discuss branch-based vs. throwaway worktrees worktree: teach `add` to recognize -d as shorthand for --detach git-checkout.txt: document -d short option for --detach
2 parents 694e517 + dccadad commit 45f462b

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

Documentation/git-checkout.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ Use `--no-guess` to disable this.
198198
Create the new branch's reflog; see linkgit:git-branch[1] for
199199
details.
200200

201+
-d::
201202
--detach::
202203
Rather than checking out a branch to work on it, check out a
203204
commit for inspection and discardable experiments.

Documentation/git-worktree.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,18 @@ A repository has one main working tree (if it's not a
3232
bare repository) and zero or more linked working trees. When you are done
3333
with a linked working tree, remove it with `git worktree remove`.
3434

35+
In its simplest form, `git worktree add <path>` automatically creates a
36+
new branch whose name is the final component of `<path>`, which is
37+
convenient if you plan to work on a new topic. For instance, `git
38+
worktree add ../hotfix` creates new branch `hotfix` and checks it out at
39+
path `../hotfix`. To instead work on an existing branch in a new working
40+
tree, use `git worktree add <path> <branch>`. On the other hand, if you
41+
just plan to make some experimental changes or do testing without
42+
disturbing existing development, it is often convenient to create a
43+
'throwaway' working tree not associated with any branch. For instance,
44+
`git worktree add -d <path>` creates a new working tree with a detached
45+
`HEAD` at the same commit as the current branch.
46+
3547
If a working tree is deleted without using `git worktree remove`, then
3648
its associated administrative files, which reside in the repository
3749
(see "DETAILS" below), will eventually be removed automatically (see
@@ -164,6 +176,7 @@ To remove a locked working tree, specify `--force` twice.
164176
exists. `-B` overrides this safeguard, resetting `<new-branch>` to
165177
`<commit-ish>`.
166178

179+
-d::
167180
--detach::
168181
With `add`, detach `HEAD` in the new working tree. See "DETACHED HEAD"
169182
in linkgit:git-checkout[1].

builtin/worktree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ static int add(int ac, const char **av, const char *prefix)
555555
N_("create a new branch")),
556556
OPT_STRING('B', NULL, &new_branch_force, N_("branch"),
557557
N_("create or reset a branch")),
558-
OPT_BOOL(0, "detach", &opts.detach, N_("detach HEAD at named commit")),
558+
OPT_BOOL('d', "detach", &opts.detach, N_("detach HEAD at named commit")),
559559
OPT_BOOL(0, "checkout", &opts.checkout, N_("populate the new working tree")),
560560
OPT_BOOL(0, "lock", &opts.keep_locked, N_("keep the new working tree locked")),
561561
OPT__QUIET(&opts.quiet, N_("suppress progress reporting")),

0 commit comments

Comments
 (0)