Skip to content

Commit c670aa4

Browse files
sunshinecogitster
authored andcommitted
worktree: teach add to recognize -d as shorthand for --detach
Like `git switch` and `git checkout`, `git worktree add` can check out a branch or set up a detached HEAD. However, unlike those other commands, `git worktree add` does not understand -d as shorthand for --detach, which may confound users accustomed to using -d for this purpose. Address this shortcoming by teaching `add` to recognize -d for --detach, thus bringing it in line with the other commands. Signed-off-by: Eric Sunshine <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 07351d9 commit c670aa4

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

Documentation/git-worktree.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ To remove a locked working tree, specify `--force` twice.
143143
exists. `-B` overrides this safeguard, resetting `<new-branch>` to
144144
`<commit-ish>`.
145145

146+
-d::
146147
--detach::
147148
With `add`, detach `HEAD` in the new working tree. See "DETACHED HEAD"
148149
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)