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

Re: [PATCH/RFC] builtin-checkout: suggest creating local branch when appropriate to do so

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 14, 2009, 03:28 UTC
Message-ID
<7vfx9modqf.fsf@alter.siamese.dyndns.org>
In-Reply-To
<76718490910131805o42e8321ama85b90b7e901dc7d@mail.gmail.com>
Jay Soffian <jaysoffian@gmail.com> writes:
Show 5 quoted lines
> This doesn't help with the original problem, which was that a user
> attempted to checkout refs/remotes/origin/<name> by just saying 'git
> checkout <name>' which I happen to think should work. A lot of what I
> keep hearing in this thread seems to be in the vein of the perfect
> being the enemy of the good.

I do not think there is "perfect" nor "good" anywhere in this. It is just the proposals were either not well thought out, were not presented well, or were misunderstood, or a bit of all.

When you do not have local "frotz" branch, and do have cloned/fetched from the origin that has "frotz" branch, I am actually Ok with this

    $ git checkout frotz [--]
to do an equivalent of:
    $ git checkout -t -b frotz origin/frotz

I do not have problem with this _particular_ DWIMmery. It will not break people's expectations, other than "asking to check out non-existing ref should fail". That expectation might be logical, but I do not think it is useful.

Another reason I won't have problem with this one is that perhaps after creating a few more commits, the next day when the user does the same

    $ git checkout frotz

what will be shown is the _local_ frotz branch. Nowhere in this sequence there is any room to mistake that you somehow checked out a branch owned by somebody else (namely, origin). You started by auto-creating your local branch, worked on it, and checked it out again the next day. In other words, this is really about a shorthand to create a new local branch called "frotz" when the commit that the branch should start from is clearly unambiguous.

I have trouble with yours, on the other hand, which is to make
    $ git checkout origin/frotz
    $ git checkout v1.5.5
into
    $ git checkout -b frotz-47 origin/frotz
    $ git checkout -b v1.5.5-47 v1.5.5

(replace -47 with whatever random string you would come up with to make it unique), as it _will_ break people's expectations, and the expected behaviour to detach without polluting the local branch namespace for the purpose of sightseeing happens to be a useful one.

I also have issues with turning
    $ git checkout origin/frotz
into
    $ git checkout -b frotz origin/frotz

only when frotz does not exist locally. This will cause the "next day" problem, and also by naming the remote tracking branch, gives a wrong impression that this is about a remote branch. It should not be.

Perhaps without touching the "detached" case at all, if we limit the scope of the change that comes out of this discussion to only one case, it might result in a good trouble-free enhancement [*1*].

The new rule would be:
    "git checkout $name", when all of the following holds:
    - $name is a good name for a local branch (i.e. check-ref-format is
      happy);
    - No local branch of that name exists;
    - There is exactly one remote $remote that has $name branch; and
    - $name itself is not a good commit name (i.e. get_sha1() barfs)
    is a request to create a local branch $name, and the branch tracks the
    remote tracking branch found in the third condition [*2*].

The important point here is that this exception is _not_ about remote tracking branch but is about a rule to allow omitting -b to create and checkout a local branch when the user's intent is clear that (1) he wants to create a new one named $name, and (2) he wants to create it starting at the commit $remote/$name.

Such a change feels quite safe and I wouldn't be opposed to it.

We _could_ discuss extending the $name in the above rule to other kinds (tags and even arbitrary committish that may not even have a direct ref pointing at it), but I think they are much more problematic.

[Footnote]
*1* Yes, I know I won't try to come with a strawman.

*2* The fourth condition is to avoid taking "origin/frotz" when "origin" remote has "frotz" branch _and_ "other" remote has "origin/frotz" branch.

The remote chosen by the third condition would be "other" (because "origin" remote only has "frotz", and not "origin/frotz", the name is unique in the sense of the third condition). The fourth condition prevents this from happening, and forbids an explicit request to detach HEAD at one point (i.e. "origin/frotz") from triggering.

Previous: Jay SoffianNext: Jay Soffian
Message 72 of 91 in “builtin-checkout: suggest creating local branch when appropriate to do so”
  1. builtin-checkout: suggest creating local branch when appropriate to do soJay Soffian, Oct 5, 2009
  2. Sverre RabbelierOct 5, 2009
  3. Johannes SchindelinOct 5, 2009
  4. Sverre RabbelierOct 5, 2009
  5. Jay SoffianOct 5, 2009
  6. Jay SoffianOct 5, 2009
  7. Johannes SchindelinOct 5, 2009
  8. Jeff KingOct 5, 2009
  9. Thomas RastOct 6, 2009
  10. Johannes SchindelinOct 6, 2009
  11. Junio C HamanoOct 6, 2009
  12. Johannes SchindelinOct 6, 2009
  13. Junio C HamanoOct 6, 2009
  14. Johannes SchindelinOct 6, 2009
  15. Matthieu MoyOct 6, 2009
  16. Mikael MagnussonOct 6, 2009
  17. Johannes SchindelinOct 6, 2009
  18. Junio C HamanoOct 18, 2009
  19. 1/3 check_filename(): make verify_filename() callable without dyingJunio C Hamano, Oct 18, 2009
  20. 2/3 DWIM "git checkout frotz" to "git checkout -b frotz origin/frotz"Junio C Hamano, Oct 18, 2009
  21. Nanako ShiraishiOct 18, 2009
  22. Björn SteinbrinkOct 18, 2009
  23. Nanako ShiraishiOct 18, 2009
  24. Junio C HamanoOct 18, 2009
  25. Björn SteinbrinkOct 19, 2009
  26. 3/3 git checkout --nodwimJunio C Hamano, Oct 18, 2009
  27. Alex RiesenOct 18, 2009
  28. Junio C HamanoOct 18, 2009
  29. Use "--no-" prefix to switch off some of checkout dwimmeryAlex Riesen, Oct 18, 2009
  30. Junio C HamanoOct 18, 2009
  31. Alex RiesenOct 19, 2009
  32. Alex RiesenOct 19, 2009
  33. Junio C HamanoOct 19, 2009
  34. Alex RiesenOct 19, 2009
  35. Junio C HamanoOct 19, 2009
  36. Avery PennarunOct 21, 2009
  37. Nanako ShiraishiOct 21, 2009
  38. Junio C HamanoOct 21, 2009
  39. git checkout --no-guessJunio C Hamano, Oct 21, 2009
  40. Avery PennarunOct 21, 2009
  41. Jay SoffianOct 26, 2009
  42. Avery PennarunOct 26, 2009
  43. Johannes SchindelinOct 22, 2009
  44. Erik Faye-LundOct 22, 2009
  45. Michael J GruberOct 23, 2009
  46. Junio C HamanoOct 24, 2009
  47. David RoundyOct 24, 2009
  48. Junio C HamanoOct 24, 2009
  49. Johannes SchindelinOct 26, 2009
  50. Avery PennarunOct 26, 2009
  51. Jeff KingOct 26, 2009
  52. Avery PennarunOct 26, 2009
  53. Jeff KingOct 26, 2009
  54. Avery PennarunOct 26, 2009
  55. Jeff KingOct 5, 2009
  56. Eugene SajineOct 6, 2009
  57. Junio C HamanoOct 6, 2009
  58. Johannes SchindelinOct 12, 2009
  59. Björn SteinbrinkOct 12, 2009
  60. Thomas RastOct 12, 2009
  61. Junio C HamanoOct 12, 2009
  62. Thomas RastOct 13, 2009
  63. Junio C HamanoOct 13, 2009
  64. Junio C HamanoOct 13, 2009
  65. Thomas RastOct 13, 2009
  66. Junio C HamanoOct 13, 2009
  67. Johannes SchindelinOct 13, 2009
  68. Junio C HamanoOct 13, 2009
  69. Jeff KingOct 13, 2009
  70. Johannes SchindelinOct 13, 2009
  71. Jay SoffianOct 14, 2009
  72. Junio C HamanoOct 14, 2009
  73. Jay SoffianOct 14, 2009
  74. Junio C HamanoOct 14, 2009
  75. Uri OkrentOct 25, 2009
  76. Jeff KingOct 14, 2009
  77. Thomas RastOct 14, 2009
  78. Jakub NarebskiOct 14, 2009
  79. Johannes SixtOct 13, 2009
  80. Daniel BarkalowOct 13, 2009
  81. Junio C HamanoOct 13, 2009
  82. Daniel BarkalowOct 13, 2009
  83. Jeff KingOct 13, 2009
  84. Junio C HamanoOct 13, 2009
  85. Johannes SchindelinOct 13, 2009
  86. Thomas RastOct 14, 2009
  87. Johannes SchindelinOct 16, 2009
  88. Thomas RastOct 16, 2009
  89. Uri OkrentOct 25, 2009
  90. Junio C HamanoOct 26, 2009
  91. Björn SteinbrinkOct 13, 2009

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.