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

Re: Inconsistent behavior of the path disambiguator

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 29, 2010, 18:38 UTC
Message-ID
<7vbp6c7ski.fsf@alter.siamese.dyndns.org>
In-Reply-To
<AANLkTinM863uZfRxy_1BW1fnfEPsPo8A2m86=Wxh7XGd@mail.gmail.com>
Dun Peal <dunpealer@gmail.com> writes:
Show 5 quoted lines
> When I clone a remote that has a branch `foo`, then `git checkout foo
> --`, the path disamgiuator makes the operation fail. `git checkout
> foo` without the disambiguator works. Following that, when branch
> `foo` already exists, `git checkout foo --` works even with the
> disambiguator that caused it to fail previously.

I do not think there is any bug. You were being bitten by folks who tried to be helpful for newbies by introducing a(n arguably confusing) special case; I can see why this is confusing, though.

> $ git checkout foo --
> fatal: invalid reference: foo
Immediately after a clone you would have
    refs/heads/master
    refs/HEAD -> refs/heads/master
    refs/remotes/origin/foo
    refs/remotes/origin/whatever-else-you-have
    ...

and there is no commit that you can name with "foo" when asking git to check out some paths out of, nor there is no branch that you can name with "foo" when asking git to check out to work on it.

You can say 'origin/foo', though, in general.
> $ git checkout foo
> Branch foo set up to track remote branch foo from origin.

Asking to check out a branch "foo" in order to work on extending the history of that branch, when there is _no_ "foo", has a special magic invented by some folks to "help usability", if there is only one $remote that has "foo" in it. In this case, you have refs/remotes/origin/foo but no other refs/remotes/$frotz/foo, and this special magic kicks in.

git behaves as if you meant "git checkout -t -b foo origin/foo" but were too lazy to type that yourself in this case.

Show 5 quoted lines
> Switched to a new branch 'foo'
> $ git checkout master
> Switched to branch 'master'
> $ git checkout foo --
> Switched to branch 'foo'
This is referring to local branch "foo", there is nothing magic.
Previous: Dun PealNext: Dun Peal
Message 2 of 10 in “Inconsistent behavior of the path disambiguator”
  1. Dun PealOct 29, 2010
  2. Junio C HamanoOct 29, 2010
  3. Dun PealOct 29, 2010
  4. Re* Inconsistent behavior of the path disambiguatorJunio C Hamano, Oct 29, 2010
  5. Jonathan NiederOct 29, 2010
  6. Junio C HamanoOct 29, 2010
  7. checkout: apply Dscho's dwim even with "--" presentJonathan Nieder, Oct 29, 2010
  8. Jonathan NiederOct 29, 2010
  9. Jonathan NiederOct 30, 2010
  10. Junio C HamanoOct 31, 2010

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.