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

Re: Can't checkout branch

From
Larry Martell <larry.martell@gmail.com>
Date
Jul 14, 2020, 20:29 UTC
Message-ID
<CACwCsY4p2LSVYK3iWKes2uA0oHj-HPdo4WS0OPzuxQuG7fDbOw@mail.gmail.com>
In-Reply-To
<CAPx1GvcOpmpuPseAQDYk9pg+hfdF9KJSSSiB0fEHQrnUuPS4CA@mail.gmail.com>
On Tue, Jul 14, 2020 at 2:18 PM Chris Torek <chris.torek@gmail.com> wrote:
Show 50 quoted lines
>
> On Tue, Jul 14, 2020 at 10:04 AM Larry Martell <larry.martell@gmail.com> wrote:
> [snippage]
> > $ git fetch --all
> > Fetching origin
> >  * [new branch]      deploy     -> origin/deploy
> >
> > $ git checkout deploy
> > $ git branch
> > * master
> >
> > $ git checkout origin/deploy
> > Note: checking out 'origin/deploy'.
> >
> > You are in 'detached HEAD' state.
> >
> > I tried deleting the local repo and recloning, but I got the same
> > results. I see the branch on github. I can checkout other branches,
> > just not this one.
> >
> > What could be going on?
>
> This happens in Git versions prior to 2.23 (what Git version are
> you using?) when there is a *file or directory* named `deploy`.
>
> What is happening is that since there is no *branch* named
> deploy (yet), you can't check it out (yet).  So `git checkout
> deploy` initially fails.  The checkout command then goes on
> to try two alternatives:
>
>  1. Treat this as `git checkout -- deploy`, i.e.,
>     extract the file or subtree named `deploy` from
>     the index (discarding changes to that file or
>     subtree).
>
>  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.
Thanks for the reply - that was indeed the issue - I had a dir named deploy.
Previous: Junio C HamanoNext: Andreas Schwab
Message 4 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.