git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Sep 7, 2020, 00:02 UTC
Message-ID
<20200907000222.4717-1-sunshine@sunshineco.com>
In-Reply-To
<20200904070703.47898-1-sunshine@sunshineco.com>

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/20200904070703.47898-1-sunshine@sunshineco.com/T/ [2]: https://lore.kernel.org/git/xmqqlfhm36v2.fsf@gitster.c.googlers.com/

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 <sunshine@sunshineco.com>
     
      ## 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.
     
         Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
     
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.
     
         Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
     
-- 
2.28.0.618.gf4bc123cb7
Previous: Junio C HamanoNext: Eric Sunshine
Message 6 of 9 in “worktree: add -d shorthand for --detach & improve documentation”
  1. 0/3 worktree: add -d shorthand for --detach & improve documentationEric Sunshine, Sep 4, 2020
  2. 2/3 worktree: add -d short option for --detachEric Sunshine, Sep 4, 2020
  3. 1/3 git-checkout.txt: document -d short option for --detachEric Sunshine, Sep 4, 2020
  4. 3/3 git-worktree.txt: discuss branch-based vs. throwaway worktreesEric Sunshine, Sep 4, 2020
  5. Junio C HamanoSep 6, 2020
  6. 0/3 worktree: teach `add` -d for --detach & improve documentationEric Sunshine, Sep 7, 2020
  7. 2/3 worktree: teach `add` to recognize -d as shorthand for --detachEric Sunshine, Sep 7, 2020
  8. 1/3 git-checkout.txt: document -d short option for --detachEric Sunshine, Sep 7, 2020
  9. 3/3 git-worktree.txt: discuss branch-based vs. throwaway worktreesEric Sunshine, Sep 7, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.