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

Re: [PATCH v4 4/4] worktree: make add <path> dwim

From
Thomas Gummerer <t.gummerer@gmail.com>
Date
Nov 25, 2017, 20:06 UTC
Message-ID
<20171125200615.GA4344@hank>
In-Reply-To
<1511634365.2847.211.camel@mad-scientist.net>
On 11/25, Paul Smith wrote:
Show 50 quoted lines
> On Sat, 2017-11-25 at 17:50 +0000, Thomas Gummerer wrote:
> > This would be the output in the new version:
> > 
> >      $ git worktree add ../bla
> >      Branch 'bla' set up to track remote branch 'bla' from 'origin'.
> >      Preparing ../bla (identifier bla)
> >      HEAD is now at 4aade43 bla
> > 
> > vs. the output without the changed behaviour:
> > 
> >      $ git worktree add ../bla
> >      Preparing ../bla (identifier bla)
> >      HEAD is now at 0f215c9 initial import
> > 
> > Of course that assumes that it's used directly, not in scripts, and
> > that users will actually read the output of the command when they
> > invoke it.  Maybe these are not safe assumptions to make though, and
> > we'd rather not have this on by default then.  As I mentioned
> > previously I would prefer having this as default, but I'm happy to
> > hide this behaviour behind a flag if we want to be more careful about
> > introducing this.  Dunno?
> 
> Speaking as a simple user, I find the current behavior of Git worktree
> add very frustrating; I am constantly wanting to create worktrees for
> other peoples' branches so I can look at the code there without messing
> up my workspace, and it's really inconvenient to do that now.
> 
> Also, the current special handling of the directory name as a putative
> branch name is not helpful for me because many of the branches I need
> to examine use "/" as their separator.  I don't begrudge making that
> feature more "DWIM" for those that can use it, but hopefully some help
> is forthcoming for those who can't.
> 
> For example, I need to create a local worktree for the remote rel/1.0
> branch... what do I do?
> 
> What I want to work is this:
> 
>     git worktree add ../1.0 rel/1.0
> 
> and have it create a worktree at ../1.0, then do the equivalent of "git
> checkout rel/1.0" which includes setting up to track the remote branch.
>  But of course this doesn't work at all; I get:
> 
>     fatal: invalid reference: rel/1.0
> 
> Personally I would think it odd to have to add an extra flag to get
> what I would expect would be "normal" behavior (checkout).
> 
> But maybe that's just me.

This part is getting done in 3/4, and is definitely going to work without an additional flag, so this is (hopefully) soon going to work just as you want :)

This is less controversial because as you mentioned this currently doesn't work at all, so there are no backwards compatibility worries.

For the other case of
    git worktree add ../foo

however we currently document one behaviour, which I would like to change (I usually have branches without a / in that I want to look at) we currently document one behaviour, which I'd like to change. So in that case we are a bit worried about backwards compatibility, and how this will affect current users that have a certain expectation of how the command is supposed to work, hence the discussion of whether to hide the new behaviour behind a flag or not.

Either way, if we do put the behaviour behind a flag, I'll also add a configuration variable, which can be set to enable the new behaviour so one doesn't have to type out the flag all the time.

Previous: Paul SmithNext: Randall S. Becker
Message 6 of 36 in “make git worktree add dwim more”
  1. 0/4 make git worktree add dwim moreThomas Gummerer, Nov 22, 2017
  2. 4/4 worktree: make add <path> dwimThomas Gummerer, Nov 22, 2017
  3. Junio C HamanoNov 24, 2017
  4. Thomas GummererNov 25, 2017
  5. Paul SmithNov 25, 2017
  6. Thomas GummererNov 25, 2017
  7. Randall S. BeckerNov 25, 2017
  8. Thomas GummererNov 25, 2017
  9. Paul SmithNov 25, 2017
  10. Junio C HamanoNov 26, 2017
  11. Thomas GummererNov 26, 2017
  12. 3/4 worktree: make add <path> <branch> dwimThomas Gummerer, Nov 22, 2017
  13. Junio C HamanoNov 24, 2017
  14. 1/4 checkout: factor out functions to new lib fileThomas Gummerer, Nov 22, 2017
  15. Junio C HamanoNov 24, 2017
  16. 2/4 worktree: add --[no-]track option to the add subcommandThomas Gummerer, Nov 22, 2017
  17. Junio C HamanoNov 24, 2017
  18. Thomas GummererNov 25, 2017
  19. 0/6 make git worktree add dwim moreThomas Gummerer, Nov 26, 2017
  20. 1/6 checkout: factor out functions to new lib fileThomas Gummerer, Nov 26, 2017
  21. 2/6 worktree: add can be created from any commit-ishThomas Gummerer, Nov 26, 2017
  22. 3/6 worktree: add --[no-]track option to the add subcommandThomas Gummerer, Nov 26, 2017
  23. 4/6 worktree: make add <path> <branch> dwimThomas Gummerer, Nov 26, 2017
  24. 6/6 add worktree.guessRemote config optionThomas Gummerer, Nov 26, 2017
  25. Junio C HamanoNov 27, 2017
  26. Thomas GummererNov 27, 2017
  27. 5/6 worktree: add --guess-remote flag to add subcommandThomas Gummerer, Nov 26, 2017
  28. Junio C HamanoNov 27, 2017
  29. Thomas GummererNov 27, 2017
  30. 0/6 make git worktree add dwim moreThomas Gummerer, Nov 29, 2017
  31. 1/6 checkout: factor out functions to new lib fileThomas Gummerer, Nov 29, 2017
  32. 2/6 worktree: add can be created from any commit-ishThomas Gummerer, Nov 29, 2017
  33. 3/6 worktree: add --[no-]track option to the add subcommandThomas Gummerer, Nov 29, 2017
  34. 5/6 worktree: add --guess-remote flag to add subcommandThomas Gummerer, Nov 29, 2017
  35. 6/6 add worktree.guessRemote config optionThomas Gummerer, Nov 29, 2017
  36. 4/6 worktree: make add <path> <branch> dwimThomas Gummerer, Nov 29, 2017

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.