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

Re: [PATCH 1/1] worktree: delete branches auto-created by 'worktree add'

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Jan 6, 2020, 04:20 UTC
Message-ID
<CAPig+cQmqKiYWDWFH5eK2S6XPOi2t2+8Oas8yZa8R=bKLym3wQ@mail.gmail.com>
In-Reply-To
<CAPig+cRL5w7azdALeBKKisTZwjgU6QhBqJRzQqDENjYiaTT0oA@mail.gmail.com>
On Fri, Dec 27, 2019 at 6:05 AM Eric Sunshine <sunshine@sunshineco.com> wrote:
Show 14 quoted lines
> On Sat, Dec 14, 2019 at 11:16 AM Pratyush Yadav <me@yadavpratyush.com> wrote:
> > When no branch name is supplied to 'worktree add', it creates a new
> > branch based on the name of the directory the new worktree is located
> > in. But when the worktree is later removed, that created branch is left
> > over.
>
> This is describing the existing (intentional) behavior but doesn't
> explain why this might be annoying or problematic. To help sell the
> patch, it might make sense to say something about how the behavior can
> trip up newcomers to git-worktree, leaving them to wonder why they are
> accumulating so many branches that they weren't aware they created. A
> comment about why you think "git worktree add -d foo" is not a viable
> way to side-step the creation of unwanted branches might also be
> worthwhile.

As an alternative to this patch, would the simpler approach of improving git-worktree documentation to do a better job of pointing people at -d/--detach as a way to side-step unwanted branch creation make sense? That is, at minimum, enhance the "Description" section to prominently talk about throwaway worktrees (created with -d/--detach), and add an example to the "Examples" section (perhaps as the first example) showing creation/use/deletion of a throwaway worktree.

Some points in favor of just updating the documentation to address this issue (rather than implementing the new behavior suggested by this patch) include:

* far simpler; no code to implement or debug
* no (surprising) behavior changes
* "git worktree add -d foo" is about as easy to type and remember as
  "git worktree add foo"

Of lesser importance, it might make sense, as a followup, to add a configuration which changes the default behavior to detach instead of auto-creating a branch. I wonder if this could be piggybacked on the existing "worktree.guessremote" configuration. Or rather, retire/deprecate that configuration and add a new one which affects DWIM'ing behavior such that it becomes multi-state. Some possible values for the new configuration: "auto" (or "dwim" or whatever), "guessremote", "detach". (I haven't thought this through thoroughly, so there might be holes in my suggestion.)

There's at least one point not in favor of merely updating the documentation to promote -d/--detach more heavily, and that is that (presumably) the concept of detached HEAD is perceived as an advanced topic, so it may not be suitable for the newcomer or casual user.

Previous: Eric SunshineNext: Pratyush Yadav
Message 8 of 10 in “worktree: delete branches auto-created by 'worktree add'”
  1. 0/1 worktree: delete branches auto-created by 'worktree add'Pratyush Yadav, Dec 14, 2019
  2. 1/1 worktree: delete branches auto-created by 'worktree add'Pratyush Yadav, Dec 14, 2019
  3. Pratyush YadavDec 18, 2019
  4. Eric SunshineDec 18, 2019
  5. Eric SunshineDec 27, 2019
  6. Pratyush YadavJan 4, 2020
  7. Eric SunshineJan 5, 2020
  8. Eric SunshineJan 6, 2020
  9. Pratyush YadavJan 6, 2020
  10. Eric SunshineJan 9, 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.