{"thread":{"id":"30839","subject":"'git branch' when origin branch with same name exists","startedAt":"2012-06-19T14:51:39Z","lastAt":"2012-06-20T18:07:52Z","messageCount":19,"participants":["Ryan Lortie","jaseem abid","Michael Schubert","Angus Hammond","Konstantin Khomoutov","Philippe Vaucher","Thomas Rast","Junio C Hamano","Phil Hord","Andreas Ericsson","Matthieu Moy"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"193842","messageId":"4FE091FB.7020202@desrt.ca","threadId":"30839","inReplyTo":null,"subject":"'git branch' when origin branch with same name exists","fromName":"Ryan Lortie","fromEmail":"desrt@desrt.ca","sentAt":"2012-06-19T14:51:39Z","receivedAt":"2012-06-19T14:51:39Z","isPatch":false,"sender":{"key":"desrt@desrt.ca","avatar":null},"body":"hi,\n\nAfter helping someone on IRC who got themselves into a bit of a problem, \nI have a feature request for git.\n\nIn this case, the user wanted to checkout a branch of a module.  They did:\n\n   git clone git://git.gnome.org/gtk+\n   cd gtk+\n   git branch gtk-3-4\n\nObviously this is a user error, but it's a pretty innocent one, and puts \nthe user in a bad state.  When they figure they should have typed \"git \ncheckout gtk-3-4\" it is already too late -- they will be taken onto \ntheir locally-created copy of the master branch.\n\nSo feature request: 'git branch' should not allow creating a local \nbranch that has the same name as a branch that already exists on \n'origin' (or any remote?) without some sort of --force flag.  It could \ninstead helpfully say:\n\n   \"\"\"\n\n     The branch you are trying to create already exists on the origin.\n     Are you sure you don't want to checkout this branch using\n     'git checkout gtk-3-4'\n\n  \"\"\"\n\nor something like that.\n\nThoughts?\n"},{"id":"193843","messageId":"CAH-tXsAoRj2oE76Mrv4jGCKDbzOihPZJF+0OTEpB1Ojf7CDv8A@mail.gmail.com","threadId":"30839","inReplyTo":"4FE091FB.7020202@desrt.ca","subject":"Re: 'git branch' when origin branch with same name exists","fromName":"jaseem abid","fromEmail":"jaseemabid@gmail.com","sentAt":"2012-06-19T15:18:57Z","receivedAt":"2012-06-19T15:18:57Z","isPatch":false,"sender":{"key":"jaseemabid@gmail.com","avatar":"https://gravatar.com/avatar/8b0432c96e4d3c8a9a96c9961ee842df7b7a869744da9c25187a51a992eabd81?d=mp&s=160"},"body":"On Tue, Jun 19, 2012 at 8:21 PM, Ryan Lortie <desrt@desrt.ca> wrote:\n> hi,\n>\n> After helping someone on IRC who got themselves into a bit of a problem, I\n> have a feature request for git.\n>\n> In this case, the user wanted to checkout a branch of a module.  They did:\n>\n>  git clone git://git.gnome.org/gtk+\n>  cd gtk+\n>  git branch gtk-3-4\n>\n> Obviously this is a user error, but it's a pretty innocent one, and puts the\n> user in a bad state.  When they figure they should have typed \"git checkout\n> gtk-3-4\" it is already too late -- they will be taken onto their\n> locally-created copy of the master branch.\n>\n> So feature request: 'git branch' should not allow creating a local branch\n> that has the same name as a branch that already exists on 'origin' (or any\n> remote?) without some sort of --force flag.  It could instead helpfully say:\n>\n>  \"\"\"\n>\n>    The branch you are trying to create already exists on the origin.\n>    Are you sure you don't want to checkout this branch using\n>    'git checkout gtk-3-4'\n>\n>  \"\"\"\n>\n> or something like that.\n>\n> Thoughts?\n\nDont know much about this but to me it looks like a good feature.\n\n-- \nJaseem Abid\nhttp://jaseemabid.github.com\n"},{"id":"193844","messageId":"4FE09C39.50702@elegosoft.com","threadId":"30839","inReplyTo":"4FE091FB.7020202@desrt.ca","subject":"Re: 'git branch' when origin branch with same name exists","fromName":"Michael Schubert","fromEmail":"mschub@elegosoft.com","sentAt":"2012-06-19T15:35:21Z","receivedAt":"2012-06-19T15:35:21Z","isPatch":false,"sender":{"key":"mschub@elegosoft.com","avatar":null},"body":"On 06/19/2012 04:51 PM, Ryan Lortie wrote:\n> So feature request: 'git branch' should not allow creating a local \n> branch that has the same name as a branch that already exists on \n> 'origin' (or any remote?) without some sort of --force flag.  It could \n> instead helpfully say:\n> \n>    \"\"\"\n> \n>      The branch you are trying to create already exists on the origin.\n>      Are you sure you don't want to checkout this branch using\n>      'git checkout gtk-3-4'\n> \n>   \"\"\"\n> \n> or something like that.\n> \n> Thoughts?\n\nThis very much violates the distributed nature of Git. Everything\nis allowed, because it's *my* repository.\n"},{"id":"193845","messageId":"4FE0A0C0.2080409@desrt.ca","threadId":"30839","inReplyTo":"4FE09C39.50702@elegosoft.com","subject":"Re: 'git branch' when origin branch with same name exists","fromName":"Ryan Lortie","fromEmail":"desrt@desrt.ca","sentAt":"2012-06-19T15:54:40Z","receivedAt":"2012-06-19T15:54:40Z","isPatch":false,"sender":{"key":"desrt@desrt.ca","avatar":null},"body":"hi Michael,\n\nOn 12-06-19 11:35 AM, Michael Schubert wrote:\n> This very much violates the distributed nature of Git. Everything\n> is allowed, because it's *my* repository.\n\nIt is certainly allowed, as originally mentioned, with a --force option \nof some kind.\n\nIt is only prevented by default because it is likely you are making a \nmistake...\n\nCheers\n"},{"id":"193846","messageId":"CAOBOgRab+KSMA_ZsE8z043gm15OkXzuf2a0dF=LeyR+oJvC5mg@mail.gmail.com","threadId":"30839","inReplyTo":"4FE09C39.50702@elegosoft.com","subject":"Re: 'git branch' when origin branch with same name exists","fromName":"Angus Hammond","fromEmail":"angusgh@gmail.com","sentAt":"2012-06-19T15:57:32Z","receivedAt":"2012-06-19T15:57:32Z","isPatch":false,"sender":{"key":"angusgh@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1839397?v=4"},"body":"> This very much violates the distributed nature of Git. Everything\n> is allowed, because it's *my* repository.\n\nBy the sounds of it everything still would be allowed for a user who\nknew that they wanted to create a branch even if it did have a\nconflicting name. However (that I can think of) this is not something\nyou usually want to do, so it's reasonable to assume that when this\nhappens it's usually user error, so git should tell the user what it\nthinks they meant to do and also give them the option to carry on\nanyway (probably with a -f flag).\n\nThis is (I think) exactly what git already does with local branches.\n\nThanks\nAngus\n"},{"id":"193847","messageId":"20120619200648.2cc8a861.kostix@domain007.com","threadId":"30839","inReplyTo":"4FE091FB.7020202@desrt.ca","subject":"Re: 'git branch' when origin branch with same name exists","fromName":"Konstantin Khomoutov","fromEmail":"flatworm@users.sourceforge.net","sentAt":"2012-06-19T16:06:48Z","receivedAt":"2012-06-19T16:06:48Z","isPatch":false,"sender":{"key":"flatworm@users.sourceforge.net","avatar":null},"body":"On Tue, 19 Jun 2012 10:51:39 -0400\nRyan Lortie <desrt@desrt.ca> wrote:\n\n> After helping someone on IRC who got themselves into a bit of a\n> problem, I have a feature request for git.\n> \n> In this case, the user wanted to checkout a branch of a module.  They\n> did:\n> \n>    git clone git://git.gnome.org/gtk+\n>    cd gtk+\n>    git branch gtk-3-4\n> \n> Obviously this is a user error, but it's a pretty innocent one, and\n> puts the user in a bad state.\n> When they figure they should have\n> typed \"git checkout gtk-3-4\" it is already too late -- they will be\n> taken onto their locally-created copy of the master branch.\nHow bad this state really is?\nThe user is free to do\n$ git branch -m gtk-3-4 mygtk-3-4\nat any time after the error was detected.\n\n> So feature request: 'git branch' should not allow creating a local \n> branch that has the same name as a branch that already exists on \n> 'origin' (or any remote?) without some sort of --force flag.  It\n> could instead helpfully say:\n[...]\n> or something like that.\nThis would not protect from the obvious case when a branch has been\ncreated on the remote (by someone else) but has not been fetched yet\nand so the local repo does not know a branch with \"conflicting\"\nname do exist.\n\n> Thoughts?\nYour intention is good but I think a safety net of the kind you\npropose would be slightly over the top.\nBasically you're trying to compensate for the user error who\nthinks the \"branch\" command should take her to an already existing\nbranch while it does something completely different.\nHence preventing the `git branch gtk-3-4` command from completion\nshould there be a remote-tracking branch of the same name is just wrong\nIMO.  On the other hand, posting a hint might be OK.  I'm talking about\nsomething like this:\n\n$ git branch gtk-3-4\nThe remote \"origin\" has the branch of the same name.\nThe created branch is not set to track it.\n\nSuch a hint would state the obvious thing but it would alert a user\nwho would not expect it (and hopefully make her google or ask for\nassistance using this hint's message).\n\nAnyway, this will make each call to git-branch to perform a crawl over\nthe refs/heads hierarchy which, I think, is not worth the result.\n"},{"id":"193848","messageId":"CAGK7Mr41h3k=6S6HizAbL_n1Ma8KJkYQuqE6w1=G7DeNrbtLwQ@mail.gmail.com","threadId":"30839","inReplyTo":"4FE0A0C0.2080409@desrt.ca","subject":"Re: 'git branch' when origin branch with same name exists","fromName":"Philippe Vaucher","fromEmail":"philippe.vaucher@gmail.com","sentAt":"2012-06-19T16:17:27Z","receivedAt":"2012-06-19T16:17:27Z","isPatch":false,"sender":{"key":"philippe.vaucher@gmail.com","avatar":null},"body":">> This very much violates the distributed nature of Git. Everything\n>> is allowed, because it's *my* repository.\n>\n>\n> It is certainly allowed, as originally mentioned, with a --force option of some kind.\n>\n> It is only prevented by default because it is likely you are making a mistake...\n\n\nI second that, way more often than not it *is* a mistake to create a\nbranch with the same name as one in a remote. In the unlikely scenario\nwhere it is what you want, I think asking for a -f/--force is not too\nmuch.\n\nI think the feature request is in sync with \"git branch -d\" refusing\nto delete an unmerged branch because it's unlikely that it's what you\nwant, and forces you to use -D instead.\n\nPhilippe\n"},{"id":"193850","messageId":"4FE0B1A1.9030509@desrt.ca","threadId":"30839","inReplyTo":"20120619200648.2cc8a861.kostix@domain007.com","subject":"Re: 'git branch' when origin branch with same name exists","fromName":"Ryan Lortie","fromEmail":"desrt@desrt.ca","sentAt":"2012-06-19T17:06:41Z","receivedAt":"2012-06-19T17:06:41Z","isPatch":false,"sender":{"key":"desrt@desrt.ca","avatar":null},"body":"hi,\n\nOn 12-06-19 12:06 PM, Konstantin Khomoutov wrote:\n> How bad this state really is?\n> The user is free to do\n> $ git branch -m gtk-3-4 mygtk-3-4\n> at any time after the error was detected.\n\nThe user that makes the mistake to type 'git branch' instead of 'git \ncheckout' in the first place is unlikely to know about this.\n\n> This would not protect from the obvious case when a branch has been\n> created on the remote (by someone else) but has not been fetched yet\n> and so the local repo does not know a branch with \"conflicting\"\n> name do exist.\n\nI consider this to be a far less likely case: more of a race condition, \nreally, and nothing we can do about it.  This is no reason that we \nshould not try to fix the easier case (which is also the far more likely \ncase).\n\n> Your intention is good but I think a safety net of the kind you\n> propose would be slightly over the top.\n> Basically you're trying to compensate for the user error who\n> thinks the \"branch\" command should take her to an already existing\n> branch while it does something completely different.\n> Hence preventing the `git branch gtk-3-4` command from completion\n> should there be a remote-tracking branch of the same name is just wrong\n> IMO.  On the other hand, posting a hint might be OK.  I'm talking about\n> something like this:\n\nI'll say again: it would still be possible with an appropriate 'force' \nparameter.\n\n> Anyway, this will make each call to git-branch to perform a crawl over\n> the refs/heads hierarchy which, I think, is not worth the result.\n\nI know branching is lightweight with git, but I don't understand that \nthe operation is so performance-critical that a enumerating a directory \nand doing a few stats would be a huge issue...\n\nIf it is decided to only check the 'origin' remote then we're talking \nabout one single stat() syscall.\n\nCheers\n"},{"id":"193851","messageId":"87a9zztdxt.fsf@thomas.inf.ethz.ch","threadId":"30839","inReplyTo":"4FE091FB.7020202@desrt.ca","subject":"Re: 'git branch' when origin branch with same name exists","fromName":"Thomas Rast","fromEmail":"trast@student.ethz.ch","sentAt":"2012-06-19T17:21:50Z","receivedAt":"2012-06-19T17:21:50Z","isPatch":false,"sender":{"key":"tr@thomasrast.ch","avatar":"https://avatars.githubusercontent.com/u/153510?v=4"},"body":"Ryan Lortie <desrt@desrt.ca> writes:\n\n> In this case, the user wanted to checkout a branch of a module.  They did:\n>\n>   git clone git://git.gnome.org/gtk+\n>   cd gtk+\n>   git branch gtk-3-4\n>\n> Obviously this is a user error, but it's a pretty innocent one, and\n> puts the user in a bad state.  When they figure they should have typed\n> \"git checkout gtk-3-4\" it is already too late -- they will be taken\n> onto their locally-created copy of the master branch.\n>\n> So feature request: 'git branch' should not allow creating a local\n> branch that has the same name as a branch that already exists on\n> origin' (or any remote?) without some sort of --force flag.\n\nHow does this fit with the fact that git has forever(?) created a\n'master' branch when cloning, and usually points it at origin/master\ntoo?\n\nI honestly haven't decided whether I should like or hate your proposal,\nbut ISTM that outlawing an operation that git does on every clone is a\nbit moot.\n\n-- \nThomas Rast\ntrast@{inf,student}.ethz.ch\n"},{"id":"193854","messageId":"7vd34v17rd.fsf@alter.siamese.dyndns.org","threadId":"30839","inReplyTo":"4FE091FB.7020202@desrt.ca","subject":"Re: 'git branch' when origin branch with same name exists","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-06-19T18:22:46Z","receivedAt":"2012-06-19T18:22:46Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ryan Lortie <desrt@desrt.ca> writes:\n\n> In this case, the user wanted to checkout a branch of a module.  They did:\n>\n>   git clone git://git.gnome.org/gtk+\n>   cd gtk+\n>   git branch gtk-3-4\n>\n> Obviously this is a user error, but it's a pretty innocent one, and\n> puts the user in a bad state.  When they figure they should have typed\n> \"git checkout gtk-3-4\" it is already too late -- they will be taken\n> onto their locally-created copy of the master branch.\n>\n> So feature request: 'git branch' should not allow creating a local\n> branch that has the same name as a branch that already exists on\n> origin' (or any remote?) without some sort of --force flag.\n\nI think \"the same name\" is missing the point.  It is perfectly fine\nto have your own 'fix' branch that builds on top of what the remote\nside calls 'master', with the intention of testing what you queue on\nyour 'fix' branch locally and cherry-picking proven-good ones to\nyour 'master' before pushing the result out, even when there happens\nto be a 'fix' branch that your 'fix' branch does not have anything\nto do with on the remote side.  After all, the remote side may start\nusing the 'fix' branch _long_ _after_ you start using your 'fix'\nbranch, so checking at the branch creation time does not help you\nmuch, even if it were a problem that your local 'fix' (which you\nhave no intention to push it to the remote) and the 'fix' at the\nremote does not have any common purpose.\n\nThe same can be said for the gtk-3-4 branch, depending on the\npurpose of 'master' vs purpose of 'gtk-3-4' at the remote side.  If\n'gtk-3-4' branch were the playground to come up with the next great\nversion, and 'master' is the continuation of the current version\nwith not so earth-shattering changes, it is perfectly normal for\ndifferent contributors to fork from 'master' for their next feature\nthat they hope eventually to go to 'gtk-3-4' at the remote, and\nlocally name the branch 'gtk-3-4', build their feature, and\ndepending on how disruptive the change is, choose to integrate the\nresult into either 'master' or'gtk-3-4' at the remote after it is\ndone.  So it is not immediately clear if \"git branch gtk-3-4\" in the\nexample is a problem to begin with.\n\nGiven that \"git checkout gtk-3-4\" with recent enough Git (since\n1.7.0) DWIMs the command to do the equivalent of\n\n\tgit checkout -t gtk-3-4 origin/gtk-3-4\n\nthat is, to fork, build on top of, and to be integrated with the\n'gtk-3-4' branch at the 'origin', if you know with a reasonable\ndegree of certainty that the user should have typed \"git checkout\ngtk-3-4\" when he typed \"git branch gtk-3-4\" in the example, then it\ncould be argued that \"git branch\" could offer an advice message, but\nit is unclear how you can be sure if \"git checkout gtk-3-4\" was what\nthe user really wanted to do when he said \"git branch gtk-3-4\" in\nthe first place.\n"},{"id":"193860","messageId":"7v8vfj17de.fsf@alter.siamese.dyndns.org","threadId":"30839","inReplyTo":"87a9zztdxt.fsf@thomas.inf.ethz.ch","subject":"Re: 'git branch' when origin branch with same name exists","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-06-19T18:31:09Z","receivedAt":"2012-06-19T18:31:09Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Thomas Rast <trast@student.ethz.ch> writes:\n\n> Ryan Lortie <desrt@desrt.ca> writes:\n>\n>> In this case, the user wanted to checkout a branch of a module.  They did:\n>>\n>>   git clone git://git.gnome.org/gtk+\n>>   cd gtk+\n>>   git branch gtk-3-4\n>>\n>> Obviously this is a user error, but it's a pretty innocent one, and\n>> puts the user in a bad state.  When they figure they should have typed\n>> \"git checkout gtk-3-4\" it is already too late -- they will be taken\n>> onto their locally-created copy of the master branch.\n>>\n>> So feature request: 'git branch' should not allow creating a local\n>> branch that has the same name as a branch that already exists on\n>> origin' (or any remote?) without some sort of --force flag.\n>\n> How does this fit with the fact that git has forever(?) created a\n> 'master' branch when cloning, and usually points it at origin/master\n> too?\n\nA big difference is that it by default is set to integrate with\norigin/master.\n\n> I honestly haven't decided whether I should like or hate your proposal,\n> but ISTM that outlawing an operation that git does on every clone is a\n> bit moot.\n\nI am sympathetic to this particular example of the user regretting\nthat he has said \"git branch\" when he meant \"git checkout\", and also\nam sympathetic to the wish that \"git branch\" somehow figured out the\nsituation and offered an advice, or outsmarted the user and forbade\nthe operation. But I do not think \"git branch\" can sensibly and\ncorrectly make that decision for the user---at least I do not sense\nany of the people who is in this thread has clear idea on what to\nbase that decision on, and \"the same name appears in an existing\nremote\" is not it.  \"The same name appears, and the new branch is\nnot set to integrate with it\" may be closer, but that may forbid\nvalid use cases too much.\n"},{"id":"193878","messageId":"4FE0E493.1010308@desrt.ca","threadId":"30839","inReplyTo":"7v8vfj17de.fsf@alter.siamese.dyndns.org","subject":"Re: 'git branch' when origin branch with same name exists","fromName":"Ryan Lortie","fromEmail":"desrt@desrt.ca","sentAt":"2012-06-19T20:44:03Z","receivedAt":"2012-06-19T20:44:03Z","isPatch":false,"sender":{"key":"desrt@desrt.ca","avatar":null},"body":"hi,\n\nOn 12-06-19 02:31 PM, Junio C Hamano wrote:\n> But I do not think \"git branch\" can sensibly and\n> correctly make that decision for the user---at least I do not sense\n> any of the people who is in this thread has clear idea on what to\n> base that decision on, and \"the same name appears in an existing\n> remote\" is not it.  \"The same name appears, and the new branch is\n> not set to integrate with it\" may be closer, but that may forbid\n> valid use cases too much.\n\nMy originally intended point was that it should be prevented in the case \nwhere 'git branch' is given no additional arguments (ie: implicitly \ncreating the branch from HEAD).  Obviously it should be possible to \ncreate a 'gtk-3-4' branch that is based on the origin one.  In any case, \nI should have made that more clear.\n\nSo to restate the feature request more clearly: \"git branch X\" with no \nexplicitly specified start-point should prevent the branch \"X\" from \nbeing created when a branch with the same name already exists on a \nremote (perhaps only considering 'origin').\n\nWhen stated in this more explicit way, it becomes clear that a --force \noption would not even be required; you could just say:\n\n   git branch gtk-3-4 HEAD\n\nto make it clear that this was your intention.\n\nNobody making a casual mistake would type that in full.\n\n\nCheers\n"},{"id":"193883","messageId":"7v8vfjyolq.fsf@alter.siamese.dyndns.org","threadId":"30839","inReplyTo":"4FE0E493.1010308@desrt.ca","subject":"Re: 'git branch' when origin branch with same name exists","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-06-19T21:32:33Z","receivedAt":"2012-06-19T21:32:33Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ryan Lortie <desrt@desrt.ca> writes:\n\n> So to restate the feature request more clearly: \"git branch X\" with no\n> explicitly specified start-point should prevent the branch \"X\" from\n> being created when a branch with the same name already exists on a\n> remote (perhaps only considering 'origin').\n>\n> When stated in this more explicit way, it becomes clear that a --force\n> option would not even be required; you could just say:\n>\n>   git branch gtk-3-4 HEAD\n>\n> to make it clear that this was your intention.\n\nWon't happen.  \"git branch new-branch-name\" has always been the way\nto create from HEAD.  Suddenly requiring an extra argument is a\ngrave usability regression.\n"},{"id":"193891","messageId":"4FE0F420.4030604@desrt.ca","threadId":"30839","inReplyTo":"7v8vfjyolq.fsf@alter.siamese.dyndns.org","subject":"Re: 'git branch' when origin branch with same name exists","fromName":"Ryan Lortie","fromEmail":"desrt@desrt.ca","sentAt":"2012-06-19T21:50:24Z","receivedAt":"2012-06-19T21:50:24Z","isPatch":false,"sender":{"key":"desrt@desrt.ca","avatar":null},"body":"hi,\n\nOn 12-06-19 05:32 PM, Junio C Hamano wrote:\n> Won't happen.  \"git branch new-branch-name\" has always been the way\n> to create from HEAD.  Suddenly requiring an extra argument is a\n> grave usability regression.\n\nReminder: we're talking only about the case where an unrelated branch \nwith the same name already exists upstream...\n\nCheers\n"},{"id":"193899","messageId":"CABURp0p6Hv8=Yg1MNb_DMRM3D2JWZtGNwn_GiOfP_x3MctrJ9A@mail.gmail.com","threadId":"30839","inReplyTo":"4FE0E493.1010308@desrt.ca","subject":"Re: 'git branch' when origin branch with same name exists","fromName":"Phil Hord","fromEmail":"phil.hord@gmail.com","sentAt":"2012-06-19T23:21:31Z","receivedAt":"2012-06-19T23:21:31Z","isPatch":false,"sender":{"key":"phil.hord@gmail.com","avatar":"https://avatars.githubusercontent.com/u/123908?v=4"},"body":"On Tue, Jun 19, 2012 at 4:44 PM, Ryan Lortie <desrt@desrt.ca> wrote:\n> hi,\n>\n>\n> On 12-06-19 02:31 PM, Junio C Hamano wrote:\n>>\n>> But I do not think \"git branch\" can sensibly and\n>> correctly make that decision for the user---at least I do not sense\n>> any of the people who is in this thread has clear idea on what to\n>> base that decision on, and \"the same name appears in an existing\n>> remote\" is not it.  \"The same name appears, and the new branch is\n>> not set to integrate with it\" may be closer, but that may forbid\n>> valid use cases too much.\n>\n>\n> My originally intended point was that it should be prevented in the case\n> where 'git branch' is given no additional arguments (ie: implicitly creating\n> the branch from HEAD).  Obviously it should be possible to create a\n> 'gtk-3-4' branch that is based on the origin one.  In any case, I should\n> have made that more clear.\n>\n> So to restate the feature request more clearly: \"git branch X\" with no\n> explicitly specified start-point should prevent the branch \"X\" from being\n> created when a branch with the same name already exists on a remote (perhaps\n> only considering 'origin').\n\nI'll second the suggestion to offer advice to a user who does this,\npossibly even including \"undo\" commands in case it was a mistake.  But\nJunio is right, of course, that the request that this \"should prevent\"\nthe action it previously explicitly did -- as documented, even --  is\na non-starter.  Aside from the user interaction problem, it will also\nbreak scripts in ways that may go undetected until they wreak nasty\nhavoc on some unsuspecting git robot.\n\nMaybe you can suggest the advice verbiage which you think would have\nhelped this user.\n\nPhil\n"},{"id":"193924","messageId":"4FE18A6B.9020207@op5.se","threadId":"30839","inReplyTo":"4FE0B1A1.9030509@desrt.ca","subject":"Re: 'git branch' when origin branch with same name exists","fromName":"Andreas Ericsson","fromEmail":"ae@op5.se","sentAt":"2012-06-20T08:31:39Z","receivedAt":"2012-06-20T08:31:39Z","isPatch":false,"sender":{"key":"ae@op5.se","avatar":"https://gravatar.com/avatar/426e89595c75a8f5252dd0c989e5fabe5bcac616e68557427ad9aef6b0ca342a?d=mp&s=160"},"body":"On 06/19/2012 07:06 PM, Ryan Lortie wrote:\n> \n>> Anyway, this will make each call to git-branch to perform a crawl\n>> over the refs/heads hierarchy which, I think, is not worth the\n>> result.\n> \n> I know branching is lightweight with git, but I don't understand that\n> the operation is so performance-critical that a enumerating a\n> directory and doing a few stats would be a huge issue...\n> \n> If it is decided to only check the 'origin' remote then we're talking\n> about one single stat() syscall.\n> \n\nNot really. I don't remember which repository it was, but the \"packed-refs\"\nfeature came about as a result of one repository having in excess of 120k\nrefs. So your \"a few stat() calls\" could well end up nuking performance\ntotally for someone else, and \"one stat call for origin\" is only true if\norigin only has one ref, which is obviously not the case for some of the\nlarger projects.\n\nIn general, assuming everyone else uses a piece of software the same way\nyou do is a recipe for creating poorly performing programs.\n\n-- \nAndreas Ericsson                   andreas.ericsson@op5.se\nOP5 AB                             www.op5.se\nTel: +46 8-230225                  Fax: +46 8-230231\n\nConsidering the successes of the wars on alcohol, poverty, drugs and\nterror, I think we should give some serious thought to declaring war\non peace.\n"},{"id":"193938","messageId":"7vr4t9x51j.fsf@alter.siamese.dyndns.org","threadId":"30839","inReplyTo":"CABURp0p6Hv8=Yg1MNb_DMRM3D2JWZtGNwn_GiOfP_x3MctrJ9A@mail.gmail.com","subject":"Re: 'git branch' when origin branch with same name exists","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-06-20T17:32:40Z","receivedAt":"2012-06-20T17:32:40Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Phil Hord <phil.hord@gmail.com> writes:\n\n> Maybe you can suggest the advice verbiage which you think would have\n> helped this user.\n\nRequiring starting point and failing without --force will never\nhappen, but it could be a possible approach to issue an additional\nadvice message under reasonably narrow conditions, namely:\n\n - The starting point was not given explicitly;\n\n - It would have DWIMed to \"git checkout -t -b it origin/it\" when\n   creating the branch (I think you need to check configurations\n   like branch.autosetupmerge and existence of the tracking branch\n   remotes/origin/it); and\n\n - advice.branchNotTrackingCorrespondingRemote is not set to false.\n"},{"id":"193942","messageId":"vpqa9zxan3a.fsf@bauges.imag.fr","threadId":"30839","inReplyTo":"7vr4t9x51j.fsf@alter.siamese.dyndns.org","subject":"Re: 'git branch' when origin branch with same name exists","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@grenoble-inp.fr","sentAt":"2012-06-20T17:51:21Z","receivedAt":"2012-06-20T17:51:21Z","isPatch":false,"sender":{"key":"matthieu.moy@grenoble-inp.fr","avatar":"https://gravatar.com/avatar/72c8a2705971a25dfaff23cece15130d405685845d911aedd5667ace277f3fc5?d=mp&s=160"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Requiring starting point and failing without --force will never\n> happen, but it could be a possible approach to issue an additional\n> advice message under reasonably narrow conditions, namely:\n>\n>  - The starting point was not given explicitly;\n>\n>  - It would have DWIMed to \"git checkout -t -b it origin/it\" when\n>    creating the branch (I think you need to check configurations\n>    like branch.autosetupmerge and existence of the tracking branch\n>    remotes/origin/it); and\n>\n>  - advice.branchNotTrackingCorrespondingRemote is not set to false.\n\nI like that. Stg like\n\n$ git branch next\nCreating local branch next starting from <sha1>.\nIf you meant to checkout a new branch 'next' to track remote branch\n'next' from 'origin', run these commands now:\ngit branch -d next; git checkout next\n\n-- \nMatthieu Moy\nhttp://www-verimag.imag.fr/~moy/\n"},{"id":"193947","messageId":"7v62alx3ev.fsf@alter.siamese.dyndns.org","threadId":"30839","inReplyTo":"vpqa9zxan3a.fsf@bauges.imag.fr","subject":"Re: 'git branch' when origin branch with same name exists","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-06-20T18:07:52Z","receivedAt":"2012-06-20T18:07:52Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> writes:\n\n> Junio C Hamano <gitster@pobox.com> writes:\n>\n>> Requiring starting point and failing without --force will never\n>> happen, but it could be a possible approach to issue an additional\n>> advice message under reasonably narrow conditions, namely:\n>>\n>>  - The starting point was not given explicitly;\n>>\n>>  - It would have DWIMed to \"git checkout -t -b it origin/it\" when\n>>    creating the branch (I think you need to check configurations\n>>    like branch.autosetupmerge and existence of the tracking branch\n>>    remotes/origin/it); and\n>>\n>>  - advice.branchNotTrackingCorrespondingRemote is not set to false.\n>\n> I like that. Stg like\n>\n> $ git branch next\n> Creating local branch next starting from <sha1>.\n> If you meant to checkout a new branch 'next' to track remote branch\n> 'next' from 'origin', run these commands now:\n> git branch -d next; git checkout next\n\nOh, another precondition would be that --force was _not_ given.\n\nIt is fairly clear \"git branch -f next\" is asking to forcibly update\nan existing local 'next' to the current HEAD, not to origin/next,\nand giving the above suggestion will be mildly irritating in such a\ncase.\n"}]}