{"thread":{"id":"18284","subject":"git checkout -b origin/mybranch origin/mybranch","startedAt":"2009-03-12T11:36:03Z","lastAt":"2009-03-13T14:08:17Z","messageCount":20,"participants":["John Tapsell","Sverre Rabbelier","Johannes Schindelin","Pieter de Bie","Jeff King","Junio C Hamano","Michael J Gruber"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"107804","messageId":"43d8ce650903120436u261cb7e3p838e4a12e7b54d7d@mail.gmail.com","threadId":"18284","inReplyTo":null,"subject":"git checkout -b origin/mybranch origin/mybranch","fromName":"John Tapsell","fromEmail":"johnflux@gmail.com","sentAt":"2009-03-12T11:36:03Z","receivedAt":"2009-03-12T11:36:03Z","isPatch":false,"sender":{"key":"johnflux@gmail.com","avatar":"https://gravatar.com/avatar/25f70d4c0f96396b84a2e34bcd9bdc233462c7b4be29b5fdca8266fc53f30b0c?d=mp&s=160"},"body":"Hey all,\n\n  One of my collegues did:\n\ngit checkout origin/somebranch\n\n  git complained that they need to specify the name with -b.  So they did:\n\ngit checkout -b origin/somebranch origin/somebranch\n\n  Git accepts this with no problems, but boy - all hell broke loose.\nDoing a push or pull gave errors, because \"origin/somebranch\" is now\nambigous (since there is two of them).  They can't even:  \"git\ncheckout -b somebranch origin/somebranch\"  anymore, since\n\"origin/somebranch\" is ambigous.  It all got into a mess.\n\n  I've sort it out now, but I'd like to request that git doesn't so\neasily let the user shoot themselves in the foot.\n\n  I propose that creating a branch called  \"origin/*\" or \"remotes/*\"\ngives at _least_ a warning, and preferably an error (overrideable with\n--force for people who really really want to do it)\n\nJohn Tapsell\n"},{"id":"107806","messageId":"fabb9a1e0903120440x78b296fbka1ddcf370f5b8df@mail.gmail.com","threadId":"18284","inReplyTo":"43d8ce650903120436u261cb7e3p838e4a12e7b54d7d@mail.gmail.com","subject":"Re: git checkout -b origin/mybranch origin/mybranch","fromName":"Sverre Rabbelier","fromEmail":"srabbelier@gmail.com","sentAt":"2009-03-12T11:40:21Z","receivedAt":"2009-03-12T11:40:21Z","isPatch":false,"sender":{"key":"srabbelier@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3098?v=4"},"body":"Heya,\n\nOn Thu, Mar 12, 2009 at 12:36, John Tapsell <johnflux@gmail.com> wrote:\n>  git complained that they need to specify the name with -b.  So they did:\n>\n> git checkout -b origin/somebranch origin/somebranch\n\nSlight unrelated, do they know about -t?\n\n$ git checkout -t origin/somebranch\n\nIt will automagically create a branch named 'somebranch' tracking\n'origin/somebranch'!\n\n-- \nCheers,\n\nSverre Rabbelier\n"},{"id":"107807","messageId":"alpine.DEB.1.00.0903121240400.10279@pacific.mpi-cbg.de","threadId":"18284","inReplyTo":"43d8ce650903120436u261cb7e3p838e4a12e7b54d7d@mail.gmail.com","subject":"Re: git checkout -b origin/mybranch origin/mybranch","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2009-03-12T11:43:03Z","receivedAt":"2009-03-12T11:43:03Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Thu, 12 Mar 2009, John Tapsell wrote:\n\n>   One of my collegues did:\n> \n> git checkout origin/somebranch\n> \n>   git complained that they need to specify the name with -b.  So they did:\n> \n> git checkout -b origin/somebranch origin/somebranch\n\nYeah, a pilot error.  It should have been\n\n\t$ git checkout -t origin/somebranch\n\nI have to wonder, though, why \"git checkout origin/somebranch\" did not \ndetach your HEAD.\n\n>   Git accepts this with no problems, but boy - all hell broke loose.\n> Doing a push or pull gave errors, because \"origin/somebranch\" is now\n> ambigous (since there is two of them).\n\nI strongly doubt that it gave errors, but rather warnings.  I have a \nrepository where I get warnings all the time (it has a cvsimport and an \norigin remote), but it works without problems.\n\n>  They can't even:  \"git checkout -b somebranch origin/somebranch\"  \n> anymore, since \"origin/somebranch\" is ambigous.  It all got into a mess.\n\nI wonder why you did not just \"git branch -m somebranch\".\n\nCiao,\nDscho\n"},{"id":"107808","messageId":"43d8ce650903120448x51220ba0k660be7706acba755@mail.gmail.com","threadId":"18284","inReplyTo":"alpine.DEB.1.00.0903121240400.10279@pacific.mpi-cbg.de","subject":"Re: git checkout -b origin/mybranch origin/mybranch","fromName":"John Tapsell","fromEmail":"johnflux@gmail.com","sentAt":"2009-03-12T11:48:31Z","receivedAt":"2009-03-12T11:48:31Z","isPatch":false,"sender":{"key":"johnflux@gmail.com","avatar":"https://gravatar.com/avatar/25f70d4c0f96396b84a2e34bcd9bdc233462c7b4be29b5fdca8266fc53f30b0c?d=mp&s=160"},"body":"2009/3/12 Johannes Schindelin <Johannes.Schindelin@gmx.de>:\n> Hi,\n>\n> On Thu, 12 Mar 2009, John Tapsell wrote:\n>\n>>   One of my collegues did:\n>>\n>> git checkout origin/somebranch\n>>\n>>   git complained that they need to specify the name with -b.  So they did:\n>>\n>> git checkout -b origin/somebranch origin/somebranch\n>\n> Yeah, a pilot error.  It should have been\n>\n>        $ git checkout -t origin/somebranch\n\nMaybe the error message for \"git checkout origin/somebranch\"  should\nsuggest:  git checkout -t origin/somebranch?\n\n> I have to wonder, though, why \"git checkout origin/somebranch\" did not\n> detach your HEAD.\n\nIt did.  But that doesn't affect doing \"git checkout -b\norigin/somebranch origin/somebranch\"  afterwards.\n\n>>   Git accepts this with no problems, but boy - all hell broke loose.\n>> Doing a push or pull gave errors, because \"origin/somebranch\" is now\n>> ambigous (since there is two of them).\n>\n> I strongly doubt that it gave errors, but rather warnings.  I have a\n> repository where I get warnings all the time (it has a cvsimport and an\n> origin remote), but it works without problems.\n>\n>>  They can't even:  \"git checkout -b somebranch origin/somebranch\"\n>> anymore, since \"origin/somebranch\" is ambigous.  It all got into a mess.\n>\n> I wonder why you did not just \"git branch -m somebranch\".\n\nBecause they didn't know what on earth was going on, and git was\nspitting out errors everywhere, they were afraid git would crash.\n\nJohn\n"},{"id":"107824","messageId":"alpine.DEB.1.00.0903121357320.6335@intel-tinevez-2-302","threadId":"18284","inReplyTo":"43d8ce650903120448x51220ba0k660be7706acba755@mail.gmail.com","subject":"Re: git checkout -b origin/mybranch origin/mybranch","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2009-03-12T13:02:22Z","receivedAt":"2009-03-12T13:02:22Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Thu, 12 Mar 2009, John Tapsell wrote:\n\n> 2009/3/12 Johannes Schindelin <Johannes.Schindelin@gmx.de>:\n>\n> > On Thu, 12 Mar 2009, John Tapsell wrote:\n> >\n> >>   One of my collegues did:\n> >>\n> >> git checkout origin/somebranch\n> >>\n> >>   git complained that they need to specify the name with -b.  So they did:\n> >>\n> >> git checkout -b origin/somebranch origin/somebranch\n> >\n> > Yeah, a pilot error.  It should have been\n> >\n> >        $ git checkout -t origin/somebranch\n> \n> Maybe the error message for \"git checkout origin/somebranch\"  should\n> suggest:  git checkout -t origin/somebranch?\n> \n> > I have to wonder, though, why \"git checkout origin/somebranch\" did not\n> > detach your HEAD.\n> \n> It did.  But that doesn't affect doing \"git checkout -b\n> origin/somebranch origin/somebranch\"  afterwards.\n\nSo did the warning read something like this?\n\n-- snip --\nmoving to \"d36a18dc9cdf1dfce8632e42491b826387aa3230\" which isn't a local \nbranch\nIf you want to create a new branch from this checkout, you may do so\n(now or later) by using -b with the checkout command again. Example:\n  git checkout -b <new_branch_name>\n-- snap --\n\n?\n\nIf so, why did you not follow the recipe\n\n\t$ git checkout -b somebranch\n\nbut something like\n\n\t$ git checkout -b origin/somebranch origin/somebranch\n\n?\n\nI do not think there is a way to tell the user more explicitely what to do \nwithout insulting the user's intelligence ;-)\n\n> > I wonder why you did not just \"git branch -m somebranch\".\n> \n> Because they didn't know what on earth was going on, and git was \n> spitting out errors everywhere, they were afraid git would crash.\n\nYeah, I know those reactions.  All of a sudden, people panic, destroying \neverything in the process.  Do tell them to calm down first of all.  \nUnless you do something like \"rm -rf .git\" or \"git branch -d\", it is \nactually pretty hard to lose data with Git.\n\nCiao,\nDscho\n"},{"id":"107828","messageId":"43d8ce650903120618h79686207vaa478c54f34e26f8@mail.gmail.com","threadId":"18284","inReplyTo":"alpine.DEB.1.00.0903121357320.6335@intel-tinevez-2-302","subject":"Re: git checkout -b origin/mybranch origin/mybranch","fromName":"John Tapsell","fromEmail":"johnflux@gmail.com","sentAt":"2009-03-12T13:18:21Z","receivedAt":"2009-03-12T13:18:21Z","isPatch":false,"sender":{"key":"johnflux@gmail.com","avatar":"https://gravatar.com/avatar/25f70d4c0f96396b84a2e34bcd9bdc233462c7b4be29b5fdca8266fc53f30b0c?d=mp&s=160"},"body":"2009/3/12 Johannes Schindelin <Johannes.Schindelin@gmx.de>:\n> Hi,\n>\n> On Thu, 12 Mar 2009, John Tapsell wrote:\n>\n>> 2009/3/12 Johannes Schindelin <Johannes.Schindelin@gmx.de>:\n>>\n>> > On Thu, 12 Mar 2009, John Tapsell wrote:\n>> >\n>> >>   One of my collegues did:\n>> >>\n>> >> git checkout origin/somebranch\n>> >>\n>> >>   git complained that they need to specify the name with -b.  So they did:\n>> >>\n>> >> git checkout -b origin/somebranch origin/somebranch\n>> >\n>> > Yeah, a pilot error.  It should have been\n>> >\n>> >        $ git checkout -t origin/somebranch\n>>\n>> Maybe the error message for \"git checkout origin/somebranch\"  should\n>> suggest:  git checkout -t origin/somebranch?\n>>\n>> > I have to wonder, though, why \"git checkout origin/somebranch\" did not\n>> > detach your HEAD.\n>>\n>> It did.  But that doesn't affect doing \"git checkout -b\n>> origin/somebranch origin/somebranch\"  afterwards.\n>\n> So did the warning read something like this?\n>\n> -- snip --\n> moving to \"d36a18dc9cdf1dfce8632e42491b826387aa3230\" which isn't a local\n> branch\n> If you want to create a new branch from this checkout, you may do so\n> (now or later) by using -b with the checkout command again. Example:\n>  git checkout -b <new_branch_name>\n> -- snap --\n>\n> ?\n\nI'm really not sure what point you're trying to prove.  Yes, we all\nknow that the user made a mistake in thinking that the new_branch_name\nshould be \"origin/mybranch\".\n\nWhat I'm suggesting is that git tries to not let the user shoot\nhimself in the foot so easily.\n\nI'm saying that:\n\ngit checkout -b origin/mybranch  origin/mybranch\n\nIs probably a mistake by the user.  We should warn the user and point\nthem in the right direction.\n\nJohn\n"},{"id":"107829","messageId":"fabb9a1e0903120643r3cfefdfej560ff7edda2be6f5@mail.gmail.com","threadId":"18284","inReplyTo":"43d8ce650903120618h79686207vaa478c54f34e26f8@mail.gmail.com","subject":"Re: git checkout -b origin/mybranch origin/mybranch","fromName":"Sverre Rabbelier","fromEmail":"srabbelier@gmail.com","sentAt":"2009-03-12T13:43:02Z","receivedAt":"2009-03-12T13:43:02Z","isPatch":false,"sender":{"key":"srabbelier@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3098?v=4"},"body":"Heya,\n\nOn Thu, Mar 12, 2009 at 14:18, John Tapsell <johnflux@gmail.com> wrote:\n> Is probably a mistake by the user.  We should warn the user and point\n> them in the right direction.\n\nThe point is that we _already_ warned the user (like Dscho pointed\nout), and that(as you pointed out), it didn't work :P.\n\n-- \nCheers,\n\nSverre Rabbelier\n"},{"id":"107831","messageId":"43d8ce650903120714g782b98e8t81340546547fe98d@mail.gmail.com","threadId":"18284","inReplyTo":"fabb9a1e0903120643r3cfefdfej560ff7edda2be6f5@mail.gmail.com","subject":"Re: git checkout -b origin/mybranch origin/mybranch","fromName":"John Tapsell","fromEmail":"johnflux@gmail.com","sentAt":"2009-03-12T14:14:51Z","receivedAt":"2009-03-12T14:14:51Z","isPatch":false,"sender":{"key":"johnflux@gmail.com","avatar":"https://gravatar.com/avatar/25f70d4c0f96396b84a2e34bcd9bdc233462c7b4be29b5fdca8266fc53f30b0c?d=mp&s=160"},"body":"2009/3/12 Sverre Rabbelier <srabbelier@gmail.com>:\n> Heya,\n>\n> On Thu, Mar 12, 2009 at 14:18, John Tapsell <johnflux@gmail.com> wrote:\n>> Is probably a mistake by the user.  We should warn the user and point\n>> them in the right direction.\n>\n> The point is that we _already_ warned the user (like Dscho pointed\n> out), and that(as you pointed out), it didn't work :P.\n\nJust doing:\n\ngit branch -b origin/master origin/master\n\ngives no error or warning at all.\n\nJohn\n\n>\n> --\n> Cheers,\n>\n> Sverre Rabbelier\n>\n"},{"id":"107838","messageId":"B9479687-D936-4EE1-A5A4-663968B76EBF@ai.rug.nl","threadId":"18284","inReplyTo":"fabb9a1e0903120643r3cfefdfej560ff7edda2be6f5@mail.gmail.com","subject":"Re: git checkout -b origin/mybranch origin/mybranch","fromName":"Pieter de Bie","fromEmail":"pdebie@ai.rug.nl","sentAt":"2009-03-12T15:21:48Z","receivedAt":"2009-03-12T15:21:48Z","isPatch":false,"sender":{"key":"pdebie@ai.rug.nl","avatar":null},"body":"\nOn Mar 12, 2009, at 1:43 PM, Sverre Rabbelier wrote:\n\n> The point is that we _already_ warned the user (like Dscho pointed\n> out), and that(as you pointed out), it didn't work :P.\n\nYou can also get this in other interactions, for example:\n\n\t$ git checkout -b origin/test HEAD\n\t$ git checkout -b origin/test master\n\nyes, these might be user errors, but I still think it's not OK to  \ncreate a new ref 'refs/heads/origin/test' if there's also a 'refs/ \nremotes/origin/test' (as I've said a few months ago).\n"},{"id":"107840","messageId":"20090312153738.GA24690@coredump.intra.peff.net","threadId":"18284","inReplyTo":"B9479687-D936-4EE1-A5A4-663968B76EBF@ai.rug.nl","subject":"Re: git checkout -b origin/mybranch origin/mybranch","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2009-03-12T15:37:38Z","receivedAt":"2009-03-12T15:37:38Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Mar 12, 2009 at 03:21:48PM +0000, Pieter de Bie wrote:\n\n> You can also get this in other interactions, for example:\n>\n> \t$ git checkout -b origin/test HEAD\n> \t$ git checkout -b origin/test master\n>\n> yes, these might be user errors, but I still think it's not OK to create a \n> new ref 'refs/heads/origin/test' if there's also a 'refs/ \n> remotes/origin/test' (as I've said a few months ago).\n\nOne thing that has been missing from this discussion (and I think you\nare getting to it here) is a concrete rule for \"X is harmful, and Y is\nnot\". That is, how do we know when to warn, and then what do we do?\n\nJohn's original example was \"git checkout -b origin/test origin/test\".\nSo it's a problem that they're textually the same, but obviously there\nare more problematic cases.\n\nThe behavior I think you are implying would be something like:\n\n  When making origin/test, try to resolve_ref(\"origin/test\"); if it\n  fails, we are OK. If it succeeds, then we know we will be creating an\n  ambiguity. Complain and refuse the creation unless \"-f\" is given.\n\nThis would actually be a superset of the \"branch already exists\" case,\nso it should be pretty simple to code, and it makes for a simple rule:\nit is now \"ref already exists\".\n\nDoes that actually cover all of the problematic cases?\n\n-Peff\n"},{"id":"107843","messageId":"43d8ce650903120916yb91113fy5485813c512c8108@mail.gmail.com","threadId":"18284","inReplyTo":"20090312153738.GA24690@coredump.intra.peff.net","subject":"Re: git checkout -b origin/mybranch origin/mybranch","fromName":"John Tapsell","fromEmail":"johnflux@gmail.com","sentAt":"2009-03-12T16:16:09Z","receivedAt":"2009-03-12T16:16:09Z","isPatch":false,"sender":{"key":"johnflux@gmail.com","avatar":"https://gravatar.com/avatar/25f70d4c0f96396b84a2e34bcd9bdc233462c7b4be29b5fdca8266fc53f30b0c?d=mp&s=160"},"body":"2009/3/12 Jeff King <peff@peff.net>:\n> On Thu, Mar 12, 2009 at 03:21:48PM +0000, Pieter de Bie wrote:\n>\n>> You can also get this in other interactions, for example:\n>>\n>>       $ git checkout -b origin/test HEAD\n>>       $ git checkout -b origin/test master\n>>\n>> yes, these might be user errors, but I still think it's not OK to create a\n>> new ref 'refs/heads/origin/test' if there's also a 'refs/\n>> remotes/origin/test' (as I've said a few months ago).\n>\n> One thing that has been missing from this discussion (and I think you\n> are getting to it here) is a concrete rule for \"X is harmful, and Y is\n> not\". That is, how do we know when to warn, and then what do we do?\n>\n> John's original example was \"git checkout -b origin/test origin/test\".\n> So it's a problem that they're textually the same, but obviously there\n> are more problematic cases.\n>\n> The behavior I think you are implying would be something like:\n>\n>  When making origin/test, try to resolve_ref(\"origin/test\"); if it\n>  fails, we are OK. If it succeeds, then we know we will be creating an\n>  ambiguity. Complain and refuse the creation unless \"-f\" is given.\n>\n> This would actually be a superset of the \"branch already exists\" case,\n> so it should be pretty simple to code, and it makes for a simple rule:\n> it is now \"ref already exists\".\n\n+1\n\nI was thinking more along the lines of checking if it begins with\nremotes/, origin/, tags/, stash/, bisect/    and blacklisting these.\n\nCan anyone suggest a reason that you really might want to create a\nbranch called  origin/something ?\n\n\n> Does that actually cover all of the problematic cases?\n>\n> -Peff\n>\n"},{"id":"107844","messageId":"20090312163533.GA28205@coredump.intra.peff.net","threadId":"18284","inReplyTo":"43d8ce650903120916yb91113fy5485813c512c8108@mail.gmail.com","subject":"Re: git checkout -b origin/mybranch origin/mybranch","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2009-03-12T16:35:33Z","receivedAt":"2009-03-12T16:35:33Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Mar 12, 2009 at 04:16:09PM +0000, John Tapsell wrote:\n\n> I was thinking more along the lines of checking if it begins with\n> remotes/, origin/, tags/, stash/, bisect/    and blacklisting these.\n> \n> Can anyone suggest a reason that you really might want to create a\n> branch called  origin/something ?\n\nThe name \"origin\" is simply convention. So if you are thinking about\nblacklisting \"origin/*\", then it is certainly possible to have a false\npositive (although as you note, it is unlikely). But what is worse is\nthat it is very likely for you to have a false negative if you use a\ndifferent remote name (and people often do if they have multiple\nremotes).\n\nFor example, in one of my projects where I do integration, \"origin\" is\nmy own public repo, and I have a remote pointing to the public repo of a\nnumber of other developers from whom I pull. So I would encounter the\nsame error by doing:\n\n  git checkout -b mike/master mike/master\n\nbut it would not be caught by your rule.\n\nOne area where your rule _is_ nicer than mine is that mine only looks at\nwhat exists _now_ and doesn't future-proof you at all. So I could say\n\n  git checkout -b origin/newtopic\n\nwhich might not be ambiguous. But if the remote adds a \"newtopic\"\nbranch, then the next time I fetch it will _become_ ambiguous.\n\nPotentially you could blacklist \"X/*\" for every remote.X.* that\nexists in your config. Even that, of course, isn't future-proof against\nyou creating a new remote. :)\n\nI think the future-proofing is probably not worth the effort. Catching\nthings that are ambiguous _now_ will cover the \"oops, I typed the wrong\nthing\" case, which I think is really the issue.\n\n-Peff\n"},{"id":"107847","messageId":"EAF5D3F1-32F2-4BF3-9B10-F91C17D06A6A@ai.rug.nl","threadId":"18284","inReplyTo":"20090312163533.GA28205@coredump.intra.peff.net","subject":"Re: git checkout -b origin/mybranch origin/mybranch","fromName":"Pieter de Bie","fromEmail":"pdebie@ai.rug.nl","sentAt":"2009-03-12T16:40:10Z","receivedAt":"2009-03-12T16:40:10Z","isPatch":false,"sender":{"key":"pdebie@ai.rug.nl","avatar":null},"body":"\nOn Mar 12, 2009, at 4:35 PM, Jeff King wrote:\n\n> I think the future-proofing is probably not worth the effort. Catching\n> things that are ambiguous _now_ will cover the \"oops, I typed the  \n> wrong\n> thing\" case, which I think is really the issue.\n\nExactly, that's the common case where things go wrong. I guess using  \ndwim_ref\nshould be DWIM enough? :)\n\n- Pieter\n"},{"id":"107846","messageId":"43d8ce650903120945h7063e7baraa3911d2cf63d1d8@mail.gmail.com","threadId":"18284","inReplyTo":"20090312163533.GA28205@coredump.intra.peff.net","subject":"Re: git checkout -b origin/mybranch origin/mybranch","fromName":"John Tapsell","fromEmail":"johnflux@gmail.com","sentAt":"2009-03-12T16:45:21Z","receivedAt":"2009-03-12T16:45:21Z","isPatch":false,"sender":{"key":"johnflux@gmail.com","avatar":"https://gravatar.com/avatar/25f70d4c0f96396b84a2e34bcd9bdc233462c7b4be29b5fdca8266fc53f30b0c?d=mp&s=160"},"body":"2009/3/12 Jeff King <peff@peff.net>:\n> On Thu, Mar 12, 2009 at 04:16:09PM +0000, John Tapsell wrote:\n>\n>> I was thinking more along the lines of checking if it begins with\n>> remotes/, origin/, tags/, stash/, bisect/    and blacklisting these.\n>>\n>> Can anyone suggest a reason that you really might want to create a\n>> branch called  origin/something ?\n>\n> The name \"origin\" is simply convention. So if you are thinking about\n> blacklisting \"origin/*\", then it is certainly possible to have a false\n> positive (although as you note, it is unlikely). But what is worse is\n> that it is very likely for you to have a false negative if you use a\n> different remote name (and people often do if they have multiple\n> remotes).\n>\n> For example, in one of my projects where I do integration, \"origin\" is\n> my own public repo, and I have a remote pointing to the public repo of a\n> number of other developers from whom I pull. So I would encounter the\n> same error by doing:\n>\n>  git checkout -b mike/master mike/master\n>\n> but it would not be caught by your rule.\n>\n> One area where your rule _is_ nicer than mine is that mine only looks at\n> what exists _now_ and doesn't future-proof you at all. So I could say\n>\n>  git checkout -b origin/newtopic\n>\n> which might not be ambiguous. But if the remote adds a \"newtopic\"\n> branch, then the next time I fetch it will _become_ ambiguous.\n>\n> Potentially you could blacklist \"X/*\" for every remote.X.* that\n> exists in your config. Even that, of course, isn't future-proof against\n> you creating a new remote. :)\n>\n> I think the future-proofing is probably not worth the effort. Catching\n> things that are ambiguous _now_ will cover the \"oops, I typed the wrong\n> thing\" case, which I think is really the issue.\n\nYep, makes sense.\n\nI suppose you could do both.  Blacklist and check if it already\nexists, but I think just checking if it exists is \"good enough\".\n\nJohn\n"},{"id":"107850","messageId":"20090312165153.GA28401@coredump.intra.peff.net","threadId":"18284","inReplyTo":"EAF5D3F1-32F2-4BF3-9B10-F91C17D06A6A@ai.rug.nl","subject":"Re: git checkout -b origin/mybranch origin/mybranch","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2009-03-12T16:51:53Z","receivedAt":"2009-03-12T16:51:53Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Mar 12, 2009 at 04:40:10PM +0000, Pieter de Bie wrote:\n\n>> I think the future-proofing is probably not worth the effort.\n>> Catching things that are ambiguous _now_ will cover the \"oops, I\n>> typed the wrong thing\" case, which I think is really the issue.\n>\n> Exactly, that's the common case where things go wrong. I guess using\n> dwim_ref should be DWIM enough? :)\n\nHmm. Yeah, I mispoke before: I should have said dwim_ref instead of\nresolve_ref (which doesn't dwym :) ).\n\nHere's a sloppy patch that I think does what you want; but it might make\nmore sense to just iterate over ref_rev_parse_rules ourselves, as\ndwim_ref does more than we care about (and we should probably\ndifferentiate between \"a branch already exists\" and \"this would make an\nambiguous ref\").\n\n---\ndiff --git a/branch.c b/branch.c\nindex d20fb04..409f445 100644\n--- a/branch.c\n+++ b/branch.c\n@@ -122,6 +122,7 @@ void create_branch(const char *head,\n \tunsigned char sha1[20];\n \tchar *real_ref, msg[PATH_MAX + 20];\n \tstruct strbuf ref = STRBUF_INIT;\n+\tchar *junk;\n \tint forcing = 0;\n \tint len;\n \n@@ -135,7 +136,8 @@ void create_branch(const char *head,\n \tif (check_ref_format(ref.buf))\n \t\tdie(\"'%s' is not a valid branch name.\", name);\n \n-\tif (resolve_ref(ref.buf, sha1, 1, NULL)) {\n+\tif (dwim_ref(name, strlen(name), sha1, &junk)) {\n+\t\tfree(junk);\n \t\tif (!force)\n \t\t\tdie(\"A branch named '%s' already exists.\", name);\n \t\telse if (!is_bare_repository() && !strcmp(head, name))\n"},{"id":"107851","messageId":"43d8ce650903120958n18baf6c0w9d083976b52d6e40@mail.gmail.com","threadId":"18284","inReplyTo":"20090312165153.GA28401@coredump.intra.peff.net","subject":"Re: git checkout -b origin/mybranch origin/mybranch","fromName":"John Tapsell","fromEmail":"johnflux@gmail.com","sentAt":"2009-03-12T16:58:22Z","receivedAt":"2009-03-12T16:58:22Z","isPatch":false,"sender":{"key":"johnflux@gmail.com","avatar":"https://gravatar.com/avatar/25f70d4c0f96396b84a2e34bcd9bdc233462c7b4be29b5fdca8266fc53f30b0c?d=mp&s=160"},"body":"2009/3/12 Jeff King <peff@peff.net>:\n> On Thu, Mar 12, 2009 at 04:40:10PM +0000, Pieter de Bie wrote:\n>\n>>> I think the future-proofing is probably not worth the effort.\n>>> Catching things that are ambiguous _now_ will cover the \"oops, I\n>>> typed the wrong thing\" case, which I think is really the issue.\n>>\n>> Exactly, that's the common case where things go wrong. I guess using\n>> dwim_ref should be DWIM enough? :)\n>\n> Hmm. Yeah, I mispoke before: I should have said dwim_ref instead of\n> resolve_ref (which doesn't dwym :) ).\n>\n> Here's a sloppy patch that I think does what you want; but it might make\n> more sense to just iterate over ref_rev_parse_rules ourselves, as\n> dwim_ref does more than we care about (and we should probably\n> differentiate between \"a branch already exists\" and \"this would make an\n> ambiguous ref\").\n>\n> ---\n> diff --git a/branch.c b/branch.c\n> index d20fb04..409f445 100644\n> --- a/branch.c\n> +++ b/branch.c\n> @@ -122,6 +122,7 @@ void create_branch(const char *head,\n>        unsigned char sha1[20];\n>        char *real_ref, msg[PATH_MAX + 20];\n>        struct strbuf ref = STRBUF_INIT;\n> +       char *junk;\n>        int forcing = 0;\n>        int len;\n>\n> @@ -135,7 +136,8 @@ void create_branch(const char *head,\n>        if (check_ref_format(ref.buf))\n>                die(\"'%s' is not a valid branch name.\", name);\n>\n> -       if (resolve_ref(ref.buf, sha1, 1, NULL)) {\n> +       if (dwim_ref(name, strlen(name), sha1, &junk)) {\n> +               free(junk);\n\nPresumably 'junk' is the resolved name?  I wonder if it's worth\nputting this info in the error message?\n\n>                if (!force)\n>                        die(\"A branch named '%s' already exists.\", name);\n\n>                        die(\"A branch named '%s' already exists (%s).\", name, junk);\n\nThat would give  \"A branched named 'origin/master' already exists\n(refs/remotes/origin/master)\"  right?\n\nDunno if it's worth it, just wondering.\n"},{"id":"107854","messageId":"20090312171420.GA2192@coredump.intra.peff.net","threadId":"18284","inReplyTo":"43d8ce650903120958n18baf6c0w9d083976b52d6e40@mail.gmail.com","subject":"Re: git checkout -b origin/mybranch origin/mybranch","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2009-03-12T17:14:20Z","receivedAt":"2009-03-12T17:14:20Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Mar 12, 2009 at 04:58:22PM +0000, John Tapsell wrote:\n\n> > -       if (resolve_ref(ref.buf, sha1, 1, NULL)) {\n> > +       if (dwim_ref(name, strlen(name), sha1, &junk)) {\n> > +               free(junk);\n> \n> Presumably 'junk' is the resolved name?  I wonder if it's worth\n> putting this info in the error message?\n\nHey, I said it was sloppy, right? ;)\n\nHere's your suggestion, plus specifying which situation (existing branch\nor ambiguous ref) would occur. It would still need tests. But I'm\ncurious to hear more opinions on this direction before cleaning it up\nmuch more (at the very least, it needs some tests).\n\n--- a/branch.c\n+++ b/branch.c\n@@ -133,6 +133,7 @@ void create_branch(const char *head,\n \tunsigned char sha1[20];\n \tchar *real_ref, msg[PATH_MAX + 20];\n \tstruct strbuf ref = STRBUF_INIT;\n+\tchar *existing;\n \tint forcing = 0;\n \tint len;\n \n@@ -146,12 +147,18 @@ void create_branch(const char *head,\n \tif (check_ref_format(ref.buf))\n \t\tdie(\"'%s' is not a valid branch name.\", name);\n \n-\tif (resolve_ref(ref.buf, sha1, 1, NULL)) {\n-\t\tif (!force)\n-\t\t\tdie(\"A branch named '%s' already exists.\", name);\n+\tif (dwim_ref(name, strlen(name), sha1, &existing)) {\n+\t\tif (!force) {\n+\t\t\tif (!prefixcmp(existing, \"refs/heads/\"))\n+\t\t\t\tdie(\"A branch named '%s' already exists.\",\n+\t\t\t\t    name);\n+\t\t\tdie(\"Creating '%s' would be ambiguous with\"\n+\t\t\t    \" the existing %s\", name, existing);\n+\t\t}\n \t\telse if (!is_bare_repository() && !strcmp(head, name))\n \t\t\tdie(\"Cannot force update the current branch.\");\n \t\tforcing = 1;\n+\t\tfree(existing);\n \t}\n \n \treal_ref = NULL;\n"},{"id":"107856","messageId":"43d8ce650903121045s74584d97o708d4f8fd2baf664@mail.gmail.com","threadId":"18284","inReplyTo":"20090312171420.GA2192@coredump.intra.peff.net","subject":"Re: git checkout -b origin/mybranch origin/mybranch","fromName":"John Tapsell","fromEmail":"johnflux@gmail.com","sentAt":"2009-03-12T17:45:56Z","receivedAt":"2009-03-12T17:45:56Z","isPatch":false,"sender":{"key":"johnflux@gmail.com","avatar":"https://gravatar.com/avatar/25f70d4c0f96396b84a2e34bcd9bdc233462c7b4be29b5fdca8266fc53f30b0c?d=mp&s=160"},"body":"2009/3/12 Jeff King <peff@peff.net>:\n> On Thu, Mar 12, 2009 at 04:58:22PM +0000, John Tapsell wrote:\n>\n>> > -       if (resolve_ref(ref.buf, sha1, 1, NULL)) {\n>> > +       if (dwim_ref(name, strlen(name), sha1, &junk)) {\n>> > +               free(junk);\n>>\n>> Presumably 'junk' is the resolved name?  I wonder if it's worth\n>> putting this info in the error message?\n>\n> Hey, I said it was sloppy, right? ;)\n>\n> Here's your suggestion, plus specifying which situation (existing branch\n> or ambiguous ref) would occur. It would still need tests. But I'm\n> curious to hear more opinions on this direction before cleaning it up\n> much more (at the very least, it needs some tests).\n\nI like :-)  Just minor comments:\n\n> --- a/branch.c\n> +++ b/branch.c\n> @@ -133,6 +133,7 @@ void create_branch(const char *head,\n>        unsigned char sha1[20];\n>        char *real_ref, msg[PATH_MAX + 20];\n>        struct strbuf ref = STRBUF_INIT;\n> +       char *existing;\n\nDon't suppose you could set this NULL.  Just in case dwim_ref doesn't\nset &existing for whatever reason.\n\n>        int forcing = 0;\n>        int len;\n>\n> @@ -146,12 +147,18 @@ void create_branch(const char *head,\n>        if (check_ref_format(ref.buf))\n>                die(\"'%s' is not a valid branch name.\", name);\n>\n> -       if (resolve_ref(ref.buf, sha1, 1, NULL)) {\n> -               if (!force)\n> -                       die(\"A branch named '%s' already exists.\", name);\n> +       if (dwim_ref(name, strlen(name), sha1, &existing)) {\n> +               if (!force) {\n> +                       if (!prefixcmp(existing, \"refs/heads/\"))\n> +                               die(\"A branch named '%s' already exists.\",\n> +                                   name);\n> +                       die(\"Creating '%s' would be ambiguous with\"\n> +                           \" the existing %s\", name, existing);\n\nMaybe put single quotes around the second %s, for consistency with the first?\n\n> +               }\n>                else if (!is_bare_repository() && !strcmp(head, name))\n>                        die(\"Cannot force update the current branch.\");\n>                forcing = 1;\n> +               free(existing);\n>        }\n>\n>        real_ref = NULL;\n>\n"},{"id":"107862","messageId":"7vbps6lhjq.fsf@gitster.siamese.dyndns.org","threadId":"18284","inReplyTo":"43d8ce650903120618h79686207vaa478c54f34e26f8@mail.gmail.com","subject":"Re: git checkout -b origin/mybranch origin/mybranch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-03-12T18:31:05Z","receivedAt":"2009-03-12T18:31:05Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"John Tapsell <johnflux@gmail.com> writes:\n\n> I'm saying that:\n>\n> git checkout -b origin/mybranch  origin/mybranch\n>\n> Is probably a mistake by the user.  We should warn the user and point\n> them in the right direction.\n\nGiven Finn Arne Gangstad's use case in a nearby thread, I do not think you\ncan so easily declare that it is a mistake by the user.\n\nWe have traditionally encouraged people to track remote origin/<name> with\nmatching local <name>, but in a workflow that interact with multiple\nremotes, one obvious way to map would be to track remote origin/<name>\nwith local origin/<name> branch.  You can say remotes/origin/<name> when\nyou mean the remote tracking one, and say heads/origin/<name> when you\nmean the local one, in order to disambiguate in such a setting.\n"},{"id":"107950","messageId":"49BA68D1.2070102@drmicha.warpmail.net","threadId":"18284","inReplyTo":"43d8ce650903120714g782b98e8t81340546547fe98d@mail.gmail.com","subject":"Re: git checkout -b origin/mybranch origin/mybranch","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2009-03-13T14:08:17Z","receivedAt":"2009-03-13T14:08:17Z","isPatch":false,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"John Tapsell venit, vidit, dixit 12.03.2009 15:14:\n> 2009/3/12 Sverre Rabbelier <srabbelier@gmail.com>:\n>> Heya,\n>>\n>> On Thu, Mar 12, 2009 at 14:18, John Tapsell <johnflux@gmail.com> wrote:\n>>> Is probably a mistake by the user.  We should warn the user and point\n>>> them in the right direction.\n>>\n>> The point is that we _already_ warned the user (like Dscho pointed\n>> out), and that(as you pointed out), it didn't work :P.\n> \n> Just doing:\n> \n> git branch -b origin/master origin/master\n> \n> gives no error or warning at all.\n\n...and it really should not. If you have a repo with lots of remotes and\ntracking branches, it makes a lot of sense to have a local branch\nreponame/branchname which tracks the remote branch reponame/branchname.\nNote that the first is refs/heads/reponame/branchname whereas the latter\nis refs/remotes/reponame/branchname. It gives warnings when it's\nambiguous, yay.\n\nMichael J Gruber\n"}]}