{"thread":{"id":"53857","subject":"Can't checkout branch","startedAt":"2020-07-14T17:00:01Z","lastAt":"2020-07-15T14:51:04Z","messageCount":6,"participants":["Larry Martell","Chris Torek","Junio C Hamano","Andreas Schwab"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"401554","messageId":"CACwCsY7P5NiQL5ajHMOWo2EPiQZKUj_m_AVbtGy=z=twChimjw@mail.gmail.com","threadId":"53857","inReplyTo":"CACwCsY7YSn_mbtFv3QjL5dY80G6e_r-gGC3SGo5rO5b8LGXxVA@mail.gmail.com","subject":"Can't checkout branch","fromName":"Larry Martell","fromEmail":"larry.martell@gmail.com","sentAt":"2020-07-14T16:59:21Z","receivedAt":"2020-07-14T17:00:01Z","isPatch":false,"sender":{"key":"larry.martell@gmail.com","avatar":"https://gravatar.com/avatar/313d9bd902360d7f418940cc0b9ae47593b1b2ac2f606bb1621102c15705eca1?d=mp&s=160"},"body":"Been using git for a long time, first time I have seen this. I am\nunable to checkout a branch.\n\n$ git status\n# On branch master\nnothing to commit, working directory clean\n\n$ git fetch --all\nFetching origin\n * [new branch]      deploy     -> origin/deploy\n\n$ git checkout deploy\n$ git branch\n* master\n\n$ git checkout origin/deploy\nNote: checking out 'origin/deploy'.\n\nYou are in 'detached HEAD' state.\n\nI tried deleting the local repo and recloning, but I got the same\nresults. I see the branch on github. I can checkout other branches,\njust not this one.\n\nWhat could be going on?\n"},{"id":"401555","messageId":"CAPx1GvcOpmpuPseAQDYk9pg+hfdF9KJSSSiB0fEHQrnUuPS4CA@mail.gmail.com","threadId":"53857","inReplyTo":"CACwCsY7P5NiQL5ajHMOWo2EPiQZKUj_m_AVbtGy=z=twChimjw@mail.gmail.com","subject":"Re: Can't checkout branch","fromName":"Chris Torek","fromEmail":"chris.torek@gmail.com","sentAt":"2020-07-14T18:17:56Z","receivedAt":"2020-07-14T18:18:09Z","isPatch":false,"sender":{"key":"chris.torek@gmail.com","avatar":"https://avatars.githubusercontent.com/u/16826774?v=4"},"body":"On Tue, Jul 14, 2020 at 10:04 AM Larry Martell <larry.martell@gmail.com> wrote:\n[snippage]\n> $ git fetch --all\n> Fetching origin\n>  * [new branch]      deploy     -> origin/deploy\n>\n> $ git checkout deploy\n> $ git branch\n> * master\n>\n> $ git checkout origin/deploy\n> Note: checking out 'origin/deploy'.\n>\n> You are in 'detached HEAD' state.\n>\n> I tried deleting the local repo and recloning, but I got the same\n> results. I see the branch on github. I can checkout other branches,\n> just not this one.\n>\n> What could be going on?\n\nThis happens in Git versions prior to 2.23 (what Git version are\nyou using?) when there is a *file or directory* named `deploy`.\n\nWhat is happening is that since there is no *branch* named\ndeploy (yet), you can't check it out (yet).  So `git checkout\ndeploy` initially fails.  The checkout command then goes on\nto try two alternatives:\n\n 1. Treat this as `git checkout -- deploy`, i.e.,\n    extract the file or subtree named `deploy` from\n    the index (discarding changes to that file or\n    subtree).\n\n 2. Treat this as `git checkout -b deploy origin/deploy`\n    or `git checkout -t origin/deploy`, i.e., create the\n    branch `deploy` from `origin/deploy`.\n\nIf *both* of these alternatives work, pre-2.23 Git *assumes* you\nmeant alternative number 1.  In 2.23 or later, `git checkout`\ntells you that this is ambiguous and makes you pick which one you\nwant.\n\nTo work around this in all versions of Git, you can just be\nmore explicit.  For instance:\n\n    git checkout deploy --\n\nforces Git to treat it as a branch name.\n\nChris\n"},{"id":"401556","messageId":"xmqqmu41lxyt.fsf@gitster.c.googlers.com","threadId":"53857","inReplyTo":"CAPx1GvcOpmpuPseAQDYk9pg+hfdF9KJSSSiB0fEHQrnUuPS4CA@mail.gmail.com","subject":"Re: Can't checkout branch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-07-14T19:04:42Z","receivedAt":"2020-07-14T19:04:56Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Chris Torek <chris.torek@gmail.com> writes:\n\n>  2. Treat this as `git checkout -b deploy origin/deploy`\n>     or `git checkout -t origin/deploy`, i.e., create the\n>     branch `deploy` from `origin/deploy`.\n>\n> If *both* of these alternatives work, pre-2.23 Git *assumes* you\n> meant alternative number 1.  In 2.23 or later, `git checkout`\n> tells you that this is ambiguous and makes you pick which one you\n> want.\n>\n> To work around this in all versions of Git, you can just be\n> more explicit.  For instance:\n>\n>     git checkout deploy --\n>\n> forces Git to treat it as a branch name.\n\nI actually think \"git checkout -t -b deploy origin/deploy\" is a\nbetter way to be explicit to avoid confusion.  You do not create a\nbranch every few seconds anyway---it is more important to instill in\nuser's head what really does go on by encouraging them to give these\ncommand line arguments explicitly, instead of teaching new people to\nrely on \"git guesses most of the time in your favor so here is the\nlazy command line\"---that will prevent true understanding and if it\nleft unremedied long enough, will result in a confused user who is\nno longer a newbie.\n\nHaving said that, yes \"git checkout deploy --\" is a way to still\nrely on git guessing most of the time in your favor to stay lazy,\nand it should work, but there may be unseen other factors to break\nthe DWIM, just like Larry didn't think of an existing file deploy\nin the working tree to be interfering.\n\nThanks.\n"},{"id":"401562","messageId":"CACwCsY4p2LSVYK3iWKes2uA0oHj-HPdo4WS0OPzuxQuG7fDbOw@mail.gmail.com","threadId":"53857","inReplyTo":"CAPx1GvcOpmpuPseAQDYk9pg+hfdF9KJSSSiB0fEHQrnUuPS4CA@mail.gmail.com","subject":"Re: Can't checkout branch","fromName":"Larry Martell","fromEmail":"larry.martell@gmail.com","sentAt":"2020-07-14T20:29:46Z","receivedAt":"2020-07-14T20:30:26Z","isPatch":false,"sender":{"key":"larry.martell@gmail.com","avatar":"https://gravatar.com/avatar/313d9bd902360d7f418940cc0b9ae47593b1b2ac2f606bb1621102c15705eca1?d=mp&s=160"},"body":"On Tue, Jul 14, 2020 at 2:18 PM Chris Torek <chris.torek@gmail.com> wrote:\n>\n> On Tue, Jul 14, 2020 at 10:04 AM Larry Martell <larry.martell@gmail.com> wrote:\n> [snippage]\n> > $ git fetch --all\n> > Fetching origin\n> >  * [new branch]      deploy     -> origin/deploy\n> >\n> > $ git checkout deploy\n> > $ git branch\n> > * master\n> >\n> > $ git checkout origin/deploy\n> > Note: checking out 'origin/deploy'.\n> >\n> > You are in 'detached HEAD' state.\n> >\n> > I tried deleting the local repo and recloning, but I got the same\n> > results. I see the branch on github. I can checkout other branches,\n> > just not this one.\n> >\n> > What could be going on?\n>\n> This happens in Git versions prior to 2.23 (what Git version are\n> you using?) when there is a *file or directory* named `deploy`.\n>\n> What is happening is that since there is no *branch* named\n> deploy (yet), you can't check it out (yet).  So `git checkout\n> deploy` initially fails.  The checkout command then goes on\n> to try two alternatives:\n>\n>  1. Treat this as `git checkout -- deploy`, i.e.,\n>     extract the file or subtree named `deploy` from\n>     the index (discarding changes to that file or\n>     subtree).\n>\n>  2. Treat this as `git checkout -b deploy origin/deploy`\n>     or `git checkout -t origin/deploy`, i.e., create the\n>     branch `deploy` from `origin/deploy`.\n>\n> If *both* of these alternatives work, pre-2.23 Git *assumes* you\n> meant alternative number 1.  In 2.23 or later, `git checkout`\n> tells you that this is ambiguous and makes you pick which one you\n> want.\n>\n> To work around this in all versions of Git, you can just be\n> more explicit.  For instance:\n>\n>     git checkout deploy --\n>\n> forces Git to treat it as a branch name.\n\nThanks for the reply - that was indeed the issue - I had a dir named deploy.\n"},{"id":"401574","messageId":"875zap8dqb.fsf@igel.home","threadId":"53857","inReplyTo":"CAPx1GvcOpmpuPseAQDYk9pg+hfdF9KJSSSiB0fEHQrnUuPS4CA@mail.gmail.com","subject":"Re: Can't checkout branch","fromName":"Andreas Schwab","fromEmail":"schwab@linux-m68k.org","sentAt":"2020-07-15T07:00:12Z","receivedAt":"2020-07-15T07:00:17Z","isPatch":false,"sender":{"key":"schwab@linux-m68k.org","avatar":"https://avatars.githubusercontent.com/u/2175493?v=4"},"body":"On Jul 14 2020, Chris Torek wrote:\n\n> To work around this in all versions of Git, you can just be\n> more explicit.  For instance:\n>\n>     git checkout deploy --\n>\n> forces Git to treat it as a branch name.\n\nFor recent versions of git, you can also use `git switch deploy'.\n\nAndreas.\n\n-- \nAndreas Schwab, schwab@linux-m68k.org\nGPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1\n\"And now for something completely different.\"\n"},{"id":"401588","messageId":"xmqq5zaoltma.fsf@gitster.c.googlers.com","threadId":"53857","inReplyTo":"875zap8dqb.fsf@igel.home","subject":"Re: Can't checkout branch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-07-15T14:50:53Z","receivedAt":"2020-07-15T14:51:04Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Andreas Schwab <schwab@linux-m68k.org> writes:\n\n> On Jul 14 2020, Chris Torek wrote:\n>\n>> To work around this in all versions of Git, you can just be\n>> more explicit.  For instance:\n>>\n>>     git checkout deploy --\n>>\n>> forces Git to treat it as a branch name.\n>\n> For recent versions of git, you can also use `git switch deploy'.\n\nYes, that is the best piece of advice in the thread so far.\n\nThanks.\n"}]}