Skip to content

worktree: teach `add` -d for --detach & improve documentation

Eric Sunshine git 2 versions – New

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest3 patches 0 repliesNew
  2. v13 patches 1 replySuperseded

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3git-checkout.txt: document -d short option for --detachDocumentation/git-checkout.txt+1 -00 replies
2/3worktree: teach `add` to recognize -d as shorthand for --detachDocumentation/git-worktree.txt builtin/worktree.c+2 -10 replies
3/3git-worktree.txt: discuss branch-based vs. throwaway worktreesDocumentation/git-worktree.txt+12 -00 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [PATCH v2 0/3] worktree: teach `add` -d for --detach & improve documentation

This is a re-roll of [1] which brings git worktree add in line with the other "checkout a branch" commands git switch and git checkout by teaching it -d as shorthand for --detach (which those other commands already understand). It also enhances git worktree documentation to emphasize that git worktree add <path> creates a new branch by default, and to discuss branch-based vs. throwaway worktrees, which may help newcomers avoid creating branches without realizing they are doing so, and later wondering why git branch --list shows branches they did not intentionally create.

v2 adjusts the commit message of [2/3] to make it clearer[2] that it teaches git worktree add (not git worktree, in general) to recognized -d as shorthand for --detach.

[1]: https://lore.kernel.org/git/[email protected]/T/
[2]: https://lore.kernel.org/git/[email protected]/

Eric Sunshine (3):
git-checkout.txt: document -d short option for --detach
worktree: teach add to recognize -d as shorthand for --detach git-worktree.txt: discuss branch-based vs. throwaway worktrees

 Documentation/git-checkout.txt |  1 +
 Documentation/git-worktree.txt | 13 +++++++++++++
 builtin/worktree.c             |  2 +-
 3 files changed, 15 insertions(+), 1 deletion(-)

Range-diff against v1:
1: 61ac1d5e14 ! 1: 538aaaf72d git-checkout.txt: document -d short option for --detach
@@ Metadata
## Commit message ##
git-checkout.txt: document -d short option for --detach

- git-checkout learned -d as short option for --detach in 163e3b2975
+ git checkout learned -d as short option for --detach in 163e3b2975
(switch: add short option for --detach, 2019-03-29) but the documentation was never updated to reflect the change.

2: 4f43ff6ddc ! 2: 49b3b3795d worktree: add -d short option for --detach
@@ Metadata
Author: Eric Sunshine <[email protected]>

## Commit message ##
- worktree: add -d short option for --detach
+ worktree: teach add to recognize -d as shorthand for --detach

- Like git-switch and git-checkout, git-worktree can check out a branch or
- set up a detached HEAD. However, unlike git-switch and git-checkout,
- git-worktree does not understand -d as shorthand for --detach, which may
- confound users accustomed to using -d for this purpose. Address this
- shortcoming by adding -d as shorthand for --detach in order to bring
- git-worktree in line with the other commands.
+ 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.

3: 628a7b7bb0 ! 3: e5de1aaf18 git-worktree.txt: discuss branch-based vs. throwaway worktrees
@@ Metadata
## Commit message ##
git-worktree.txt: discuss branch-based vs. throwaway worktrees

- By default, "git worktree add" creates a new worktree associated with a
+ By default, git worktree add creates a new worktree associated with a
particular branch (which may have been created automatically if not specified explicitly on the command-line). It is also convenient to create throwaway worktrees not associated with any branch, which can be
@@ Commit message
and throwaway worktrees is to help newcomers understand that the simplest form git worktree add <path> automatically creates a new branch. Stating this early in the description, may help newcomers avoid
- creating unwanted new branches without being aware that they are doing
- so, and later wondering why git branch --list shows branches the user
- did not intentionally create.
+ creating branches without realizing they are doing so, and later
+ wondering why git branch --list shows branches the user did not
+ intentionally create.

Signature · 1 line
2.28.0.618.gf4bc123cb7