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

Re: Can't checkout branch

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 14, 2020, 19:04 UTC
Message-ID
<xmqqmu41lxyt.fsf@gitster.c.googlers.com>
In-Reply-To
<CAPx1GvcOpmpuPseAQDYk9pg+hfdF9KJSSSiB0fEHQrnUuPS4CA@mail.gmail.com>
Chris Torek <chris.torek@gmail.com> writes:
Show 15 quoted lines
>  2. Treat this as `git checkout -b deploy origin/deploy`
>     or `git checkout -t origin/deploy`, i.e., create the
>     branch `deploy` from `origin/deploy`.
>
> If *both* of these alternatives work, pre-2.23 Git *assumes* you
> meant alternative number 1.  In 2.23 or later, `git checkout`
> tells you that this is ambiguous and makes you pick which one you
> want.
>
> To work around this in all versions of Git, you can just be
> more explicit.  For instance:
>
>     git checkout deploy --
>
> forces Git to treat it as a branch name.

I actually think "git checkout -t -b deploy origin/deploy" is a better way to be explicit to avoid confusion. You do not create a branch every few seconds anyway---it is more important to instill in user's head what really does go on by encouraging them to give these command line arguments explicitly, instead of teaching new people to rely on "git guesses most of the time in your favor so here is the lazy command line"---that will prevent true understanding and if it left unremedied long enough, will result in a confused user who is no longer a newbie.

Having said that, yes "git checkout deploy --" is a way to still rely on git guessing most of the time in your favor to stay lazy, and it should work, but there may be unseen other factors to break the DWIM, just like Larry didn't think of an existing file deploy in the working tree to be interfering.

Thanks.
Previous: Chris TorekNext: Larry Martell
Message 3 of 6 in “Can't checkout branch”
  1. Larry MartellJul 14, 2020
  2. Chris TorekJul 14, 2020
  3. Junio C HamanoJul 14, 2020
  4. Larry MartellJul 14, 2020
  5. Andreas SchwabJul 15, 2020
  6. Junio C HamanoJul 15, 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.