{"thread":{"id":"45347","subject":"git-push branch confusion caused by user mistake","startedAt":"2017-03-10T21:45:12Z","lastAt":"2017-03-13T19:50:02Z","messageCount":5,"participants":["Phil Hord","Junio C Hamano","Jakub Narębski","Jacob Keller"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"313800","messageId":"CABURp0pf=4BE=E7qeOmYAcqJb=qDeGJ1EFyfCf+hDtKjjMD=ng@mail.gmail.com","threadId":"45347","inReplyTo":null,"subject":"git-push branch confusion caused by user mistake","fromName":"Phil Hord","fromEmail":"phil.hord@gmail.com","sentAt":"2017-03-10T21:44:30Z","receivedAt":"2017-03-10T21:45:12Z","isPatch":false,"sender":{"key":"phil.hord@gmail.com","avatar":"https://avatars.githubusercontent.com/u/123908?v=4"},"body":"This week a user accidentally did this:\n\n    $ git push origin origin/master\n    Total 0 (delta 0), reused 0 (delta 0)\n    To parent.git\n     * [new branch]      origin/master -> origin/master\n\nHe saw his mistake when the \"new branch\" message appeared, but he was\nconfused about how to fix it and worried he broke something.\n\nIt seems reasonable that git expanded the original args into this one:\n\n    git push origin refs/remotes/origin/master\n\nHowever, since the dest ref was not provided, it was assumed to be the\nsame as the source ref, so it worked as if he typed this:\n\n    git push origin refs/remotes/origin/master:refs/remotes/origin/master\n\nIndeed, git ls-remote origin shows the result:\n\n    $ git ls-remote origin\n    d1ff1c9224ae5e58a7656fb9ecc95865d42ed71e HEAD\n    d1ff1c9224ae5e58a7656fb9ecc95865d42ed71e refs/heads/master\n    d1ff1c9224ae5e58a7656fb9ecc95865d42ed71e refs/remotes/origin/master\n\nAlso, I verified that this (otherwise valid) command has similar\nunexpected results:\n    $ git remote add other foo.git && git fetch other && git push\norigin other/topic\n    $ git ls-remote origin\n    d1ff1c9224ae5e58a7656fb9ecc95865d42ed71e HEAD\n    d1ff1c9224ae5e58a7656fb9ecc95865d42ed71e refs/heads/master\n    d1ff1c9224ae5e58a7656fb9ecc95865d42ed71e refs/remotes/origin/master\n    d1ff1c9224ae5e58a7656fb9ecc95865d42ed71e refs/remotes/other/topic\n\nI think git should be smarter about deducing the dest ref from the\nsource ref if the source ref is in refs/remotes, but I'm not sure how\nfar to take it.  It feels like we should translate refspecs something\nlike this for push:\n\n    origin/master\n        => refs/remotes/origin/master:refs/heads/master\n\n    refs/remotes/origin/master\n         => refs/remotes/origin/master:refs/heads/master\n\n    origin/master:origin/master\n         => refs/remotes/origin/master:refs/heads/origin/master\n\n    master:refs/remotes/origin/master\n         => refs/heads/master:refs/remotes/origin/master\n\nThat is, we should not infer a remote refspec of \"refs/remotes/*\"; we\nshould only get there if \"refs/remotes\" was given explicitly by the\nuser.\n\nDoes this seem reasonable?  I can try to work up a patch if so.\n"},{"id":"313805","messageId":"xmqqzigswzk9.fsf@gitster.mtv.corp.google.com","threadId":"45347","inReplyTo":"CABURp0pf=4BE=E7qeOmYAcqJb=qDeGJ1EFyfCf+hDtKjjMD=ng@mail.gmail.com","subject":"Re: git-push branch confusion caused by user mistake","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-03-10T22:13:10Z","receivedAt":"2017-03-10T22:13:18Z","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> I think git should be smarter about deducing the dest ref from the\n> source ref if the source ref is in refs/remotes, but I'm not sure how\n> far to take it.\n\nMy knee-jerk reaction is \"Don't take it anywhere\".  \n\nGiving a refspec from the command line is an established way to\ndefeat the default behaviour when you do not give any and only the\nremote, and making it do things behind user's back, you would be\nrobbing the escape hatch from people.\n\nIt often is useful in real-life workflow when \"git push $dest\norigin/master\" does exactly the way it works now, which I actually\nuse myself.  Imagine that you have two repositories, use one of them\nprimarily to interact with the outside world and do your work, but\nyou then occasionally push from that primary repository to the other\none, instead of logging into the host that has the other one and\nrunning a fetch on that host from the outside world.  Your \"trying\nto be clever when given a colon-less refspec\" will force people to\ntype \"git push $dest origin/master:origin/master\" in such a case.\n\n\n"},{"id":"313835","messageId":"4a60d43b-b4b2-fb8d-b139-bbbdef564187@gmail.com","threadId":"45347","inReplyTo":"CABURp0pf=4BE=E7qeOmYAcqJb=qDeGJ1EFyfCf+hDtKjjMD=ng@mail.gmail.com","subject":"Re: git-push branch confusion caused by user mistake","fromName":"Jakub Narębski","fromEmail":"jnareb@gmail.com","sentAt":"2017-03-11T20:43:34Z","receivedAt":"2017-03-11T20:43:48Z","isPatch":false,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"W dniu 10.03.2017 o 22:44, Phil Hord pisze:\n> This week a user accidentally did this:\n> \n>     $ git push origin origin/master\n>     Total 0 (delta 0), reused 0 (delta 0)\n>     To parent.git\n>      * [new branch]      origin/master -> origin/master\n> \n> He saw his mistake when the \"new branch\" message appeared, but he was\n> confused about how to fix it and worried he broke something.\n\nIt is nowadays very easy to delete accidentally created remote branch\nwith\n\n      $ git push origin --delete origin/master\n \n> It seems reasonable that git expanded the original args into this one:\n> \n>     git push origin refs/remotes/origin/master\n> \n> However, since the dest ref was not provided, it was assumed to be the\n> same as the source ref, so it worked as if he typed this:\n> \n>     git push origin refs/remotes/origin/master:refs/remotes/origin/master\n\nThis rule depends on push.default setting, but it is a very simple\nrule.  Simple is good.  DWIM is usually not worth it, unless program\ncan guess what you meant, and what you meant is always the same.\n\n> I think git should be smarter about deducing the dest ref from the\n> source ref if the source ref is in refs/remotes, but I'm not sure how\n> far to take it.  It feels like we should translate refspecs something\n> like this for push:\n> \n>     origin/master\n>         => refs/remotes/origin/master:refs/heads/master\n[...]\n\nSuch push doesn't make sense (unless you have a quite unusual situation).\n\nNote that 'origin/master', that is 'refs/remotes/origin/master' is a\nremote-tracking branch, that is a ref that is meant to track position\nof the 'master' branch ('refs/heads/master') in the 'origin' remote.\nThus it should always be the same as 'master' in 'origin', or be behind\nif you didn't fetch.\n\n> Does this seem reasonable?  I can try to work up a patch if so.\n\nThus I don't think such complication is reasonable.\n\n-- \nJakub Narębski\n \n\n"},{"id":"313878","messageId":"CA+P7+xp1T0-02=NznW0=Xd_K5_bdtg=nVgtTqT74+EJuncYxSw@mail.gmail.com","threadId":"45347","inReplyTo":"xmqqzigswzk9.fsf@gitster.mtv.corp.google.com","subject":"Re: git-push branch confusion caused by user mistake","fromName":"Jacob Keller","fromEmail":"jacob.keller@gmail.com","sentAt":"2017-03-13T08:54:55Z","receivedAt":"2017-03-13T08:55:39Z","isPatch":false,"sender":{"key":"jacob.keller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"On Fri, Mar 10, 2017 at 2:13 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> Phil Hord <phil.hord@gmail.com> writes:\n>\n>> I think git should be smarter about deducing the dest ref from the\n>> source ref if the source ref is in refs/remotes, but I'm not sure how\n>> far to take it.\n>\n> My knee-jerk reaction is \"Don't take it anywhere\".\n>\n> Giving a refspec from the command line is an established way to\n> defeat the default behaviour when you do not give any and only the\n> remote, and making it do things behind user's back, you would be\n> robbing the escape hatch from people.\n>\n> It often is useful in real-life workflow when \"git push $dest\n> origin/master\" does exactly the way it works now, which I actually\n> use myself.  Imagine that you have two repositories, use one of them\n> primarily to interact with the outside world and do your work, but\n> you then occasionally push from that primary repository to the other\n> one, instead of logging into the host that has the other one and\n> running a fetch on that host from the outside world.  Your \"trying\n> to be clever when given a colon-less refspec\" will force people to\n> type \"git push $dest origin/master:origin/master\" in such a case.\n>\n>\n\nIt might be worth having some warning or something happen here? I've\nhad several  co-workers at $DAYJOB get confused by this sort of thing.\n\nThanks,\nJake\n"},{"id":"313940","messageId":"CABURp0onBt8yo2nJhaxkZk+dujOYDD6dZDeo_a4=dMx867OPvg@mail.gmail.com","threadId":"45347","inReplyTo":"CA+P7+xp1T0-02=NznW0=Xd_K5_bdtg=nVgtTqT74+EJuncYxSw@mail.gmail.com","subject":"Re: git-push branch confusion caused by user mistake","fromName":"Phil Hord","fromEmail":"phil.hord@gmail.com","sentAt":"2017-03-13T19:49:36Z","receivedAt":"2017-03-13T19:50:02Z","isPatch":false,"sender":{"key":"phil.hord@gmail.com","avatar":"https://avatars.githubusercontent.com/u/123908?v=4"},"body":"On Mon, Mar 13, 2017 at 1:55 AM Jacob Keller <jacob.keller@gmail.com> wrote:\n> On Fri, Mar 10, 2017 at 2:13 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> > Phil Hord <phil.hord@gmail.com> writes:\n> >> I think git should be smarter about deducing the dest ref from the\n> >> source ref if the source ref is in refs/remotes, but I'm not sure how\n> >> far to take it.\n> >\n> > My knee-jerk reaction is \"Don't take it anywhere\".\n> >\n> > Giving a refspec from the command line is an established way to\n> > defeat the default behaviour when you do not give any and only the\n> > remote, and making it do things behind user's back, you would be\n> > robbing the escape hatch from people.\n>\n> It might be worth having some warning or something happen here? I've\n> had several  co-workers at $DAYJOB get confused by this sort of thing.\n\nOn one very active project at $work, we have 380,000 commits, 4600\nbranches in refs/heads and 96 branches in refs/remotes.  About half of\nthe refs/remotes (43) are obviously user errors.  The other half it's\nnot possible for me to know.\n\nI suggested to our admins to block attempts to push to\n'refs/remotes/*' so in the future users don't lose track of commits\nthey think they pushed.  But I don't know if that will really happen.\n\nThanks for the counterexample feedback.\n"}]}