{"thread":{"id":"53779","subject":"Why won't git checkout a branch?","startedAt":"2020-07-01T08:42:04Z","lastAt":"2020-07-01T15:13:44Z","messageCount":6,"participants":["Jeffrey Walton","Andreas Schwab","Chris Torek"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"400871","messageId":"CAH8yC8m1=0n8zzoW--g_XLebJFqFSXpBpTr+1S58z7snLTt-0Q@mail.gmail.com","threadId":"53779","inReplyTo":null,"subject":"Why won't git checkout a branch?","fromName":"Jeffrey Walton","fromEmail":"noloader@gmail.com","sentAt":"2020-07-01T08:41:50Z","receivedAt":"2020-07-01T08:42:04Z","isPatch":false,"sender":{"key":"noloader@gmail.com","avatar":null},"body":"Why can't I checkout a branch? What's broken this time?\n\n$ rm -rf libb2\n$ git clone https://github.com/noloader/libb2\nCloning into 'libb2'...\nremote: Enumerating objects: 39, done.\nremote: Counting objects: 100% (39/39), done.\nremote: Compressing objects: 100% (31/31), done.\nremote: Total 291 (delta 14), reused 23 (delta 8), pack-reused 252\nReceiving objects: 100% (291/291), 431.67 KiB | 4.23 MiB/s, done.\nResolving deltas: 100% (162/162), done.\n$ cd libb2\n$ git fetch --all\nFetching origin\n$ git branch -a\n* master\n  remotes/origin/HEAD -> origin/master\n  remotes/origin/autotools\n  remotes/origin/fix-bigendian\n  remotes/origin/m4\n  remotes/origin/master\n  remotes/origin/overhaul\n$ git checkout m4\n$ git branch\n* master\n"},{"id":"400877","messageId":"87tuyrd0ng.fsf@igel.home","threadId":"53779","inReplyTo":"CAH8yC8m1=0n8zzoW--g_XLebJFqFSXpBpTr+1S58z7snLTt-0Q@mail.gmail.com","subject":"Re: Why won't git checkout a branch?","fromName":"Andreas Schwab","fromEmail":"schwab@linux-m68k.org","sentAt":"2020-07-01T09:50:43Z","receivedAt":"2020-07-01T09:50:48Z","isPatch":false,"sender":{"key":"schwab@linux-m68k.org","avatar":"https://avatars.githubusercontent.com/u/2175493?v=4"},"body":"On Jul 01 2020, Jeffrey Walton wrote:\n\n> $ git checkout m4\n\nTry a newer git version:\n\n$ git checkout m4\nfatal: 'm4' could be both a local file and a tracking branch.\nPlease use -- (and optionally --no-guess) to disambiguate\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":"400883","messageId":"CAH8yC8kxY5mV0p-98W0uDN7PLxmNR4LkNcz9vbKsq21aTd-qQg@mail.gmail.com","threadId":"53779","inReplyTo":"87tuyrd0ng.fsf@igel.home","subject":"Re: Why won't git checkout a branch?","fromName":"Jeffrey Walton","fromEmail":"noloader@gmail.com","sentAt":"2020-07-01T10:09:10Z","receivedAt":"2020-07-01T10:09:26Z","isPatch":false,"sender":{"key":"noloader@gmail.com","avatar":null},"body":"On Wed, Jul 1, 2020 at 5:50 AM Andreas Schwab <schwab@linux-m68k.org> wrote:\n>\n> On Jul 01 2020, Jeffrey Walton wrote:\n>\n> > $ git checkout m4\n>\n> Try a newer git version:\n>\n> $ git checkout m4\n> fatal: 'm4' could be both a local file and a tracking branch.\n> Please use -- (and optionally --no-guess) to disambiguate\n\nAck, thanks.\n\nThis does not look normal, either. I don't want to create a new\nbranch. I want to work on the existing branch.\n\n$ git checkout origin/m4\nNote: checking out 'origin/m4'.\n\nYou are in 'detached HEAD' state. You can look around, make experimental\nchanges and commit them, and you can discard any commits you make in this\nstate without impacting any branches by performing another checkout.\n\nIf you want to create a new branch to retain commits you create, you may\ndo so (now or later) by using -b with the checkout command again. Example:\n\n  git checkout -b <new-branch-name>\n\nHEAD is now at 5c3967f Merge branch 'm4' of\nhttps://github.com/noloader/libb2 into m4\n\nJeff\n"},{"id":"400886","messageId":"87lfk3czae.fsf@igel.home","threadId":"53779","inReplyTo":"CAH8yC8kxY5mV0p-98W0uDN7PLxmNR4LkNcz9vbKsq21aTd-qQg@mail.gmail.com","subject":"Re: Why won't git checkout a branch?","fromName":"Andreas Schwab","fromEmail":"schwab@linux-m68k.org","sentAt":"2020-07-01T10:20:09Z","receivedAt":"2020-07-01T10:21:10Z","isPatch":false,"sender":{"key":"schwab@linux-m68k.org","avatar":"https://avatars.githubusercontent.com/u/2175493?v=4"},"body":"On Jul 01 2020, Jeffrey Walton wrote:\n\n> On Wed, Jul 1, 2020 at 5:50 AM Andreas Schwab <schwab@linux-m68k.org> wrote:\n>>\n>> On Jul 01 2020, Jeffrey Walton wrote:\n>>\n>> > $ git checkout m4\n>>\n>> Try a newer git version:\n>>\n>> $ git checkout m4\n>> fatal: 'm4' could be both a local file and a tracking branch.\n>> Please use -- (and optionally --no-guess) to disambiguate\n>\n> Ack, thanks.\n>\n> This does not look normal, either. I don't want to create a new\n> branch. I want to work on the existing branch.\n\nTo disambiguate, use `git checkout m4 --' if you want the branch, and\n`git checkout -- m4' if you want the local file.\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":"400889","messageId":"CAH8yC8=SgS1=mpSM_7j8FQzreVPfE5U_tnsCz9ixZoBHLUuM7A@mail.gmail.com","threadId":"53779","inReplyTo":"87lfk3czae.fsf@igel.home","subject":"Re: Why won't git checkout a branch?","fromName":"Jeffrey Walton","fromEmail":"noloader@gmail.com","sentAt":"2020-07-01T10:45:25Z","receivedAt":"2020-07-01T10:45:38Z","isPatch":false,"sender":{"key":"noloader@gmail.com","avatar":null},"body":"On Wed, Jul 1, 2020 at 6:20 AM Andreas Schwab <schwab@linux-m68k.org> wrote:\n>\n> On Jul 01 2020, Jeffrey Walton wrote:\n>\n> > On Wed, Jul 1, 2020 at 5:50 AM Andreas Schwab <schwab@linux-m68k.org> wrote:\n> >>\n> >> On Jul 01 2020, Jeffrey Walton wrote:\n> >>\n> >> > $ git checkout m4\n> >>\n> >> Try a newer git version:\n> >>\n> >> $ git checkout m4\n> >> fatal: 'm4' could be both a local file and a tracking branch.\n> >> Please use -- (and optionally --no-guess) to disambiguate\n> >\n> > Ack, thanks.\n> >\n> > This does not look normal, either. I don't want to create a new\n> > branch. I want to work on the existing branch.\n>\n> To disambiguate, use `git checkout m4 --' if you want the branch, and\n> `git checkout -- m4' if you want the local file.\n\nPerfect, thanks.\n\nSo the way to checkout that always works is to append --. Is that correct?\n\nIf so, I will start using it everywhere.\n\nJeff\n"},{"id":"400923","messageId":"CAPx1Gvc+pWe6UwRREHMkUCViYjzQgfg1jfbWy2pyFQCjhwV+Bg@mail.gmail.com","threadId":"53779","inReplyTo":"CAH8yC8kxY5mV0p-98W0uDN7PLxmNR4LkNcz9vbKsq21aTd-qQg@mail.gmail.com","subject":"Re: Why won't git checkout a branch?","fromName":"Chris Torek","fromEmail":"chris.torek@gmail.com","sentAt":"2020-07-01T15:13:30Z","receivedAt":"2020-07-01T15:13:44Z","isPatch":false,"sender":{"key":"chris.torek@gmail.com","avatar":"https://avatars.githubusercontent.com/u/16826774?v=4"},"body":"On Wed, Jul 1, 2020 at 3:10 AM Jeffrey Walton <noloader@gmail.com> wrote:\n> This does not look normal, either. I don't want to create a new\n> branch. I want to work on the existing branch.\n\nTechnically, you *have to* create a new branch here: you do\nnot have an `m4` branch (yet). Your local repository's branches\nare independent of the branches in the repository you cloned.\n\n(You could work in detached HEAD state to avoid the technical\nrequirement here but that's not practical for normal humans. :-) )\n\nThe suffix-`--` trick works in old versions of Git, creating the `m4`\nbranch from the `origin/m4` name.  If you upgrade to Git 2.23 or\nlater and use `git switch`, I think you will find that it's generally\nmore user friendly.\n\nChris\n"}]}