{"thread":{"id":"61215","subject":"Update message_advice_pull_before_push to mention how to push after rebasing","startedAt":"2024-03-28T09:54:25Z","lastAt":"2024-03-29T07:41:15Z","messageCount":6,"participants":["zhang kai","Rubén Justo","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"491735","messageId":"CAK_130T8sZUZAuvj4x7sB278kVL7ARaBv3Pg2djQB45O+7xKTg@mail.gmail.com","threadId":"61215","inReplyTo":null,"subject":"Update message_advice_pull_before_push to mention how to push after rebasing","fromName":"zhang kai","fromEmail":"kylerzhang11@gmail.com","sentAt":"2024-03-28T09:54:13Z","receivedAt":"2024-03-28T09:54:25Z","isPatch":false,"sender":{"key":"kylerzhang11@gmail.com","avatar":null},"body":"Hi all,\n\nOur team uses git rebase a lot. A common hiccup we noticed during the\ndaily work is that new devs often didn't know how to push properly\nafter the rebase.\n\nWhen someone try to push to the remote after rebasing the branch, the\npush would mostly fail with the message_advice_pull_before_push:\n\n> Updates were rejected because the tip of your current branch is behind\\n\" \"its remote counterpart. If you want to integrate the remote changes,\\n\" \"use 'git pull' before pushing again.\\n\" \"See the 'Note about fast-forwards' in 'git push --help' for details.\n\nHowever, in this situation, pull will \"invalid\" the rebasing. After\npull then push, devs often will be surprised by the merge/pull request\ncontaining diffs that should not be in this branch. In this case, we\noften should just do `git push --force-with-lease`.\n\nIf we add a message like \"If you just rebased your branch, please\nconsider 'git push --force-with-lease'\" to the\nmessage_adivce_pull_before_push, we may save devs some time figuring\nout what's wrong with their branch. If this is acceptable, we'd be\nhappy to prepare a patch.\n\nThanks,\nKai\n"},{"id":"491746","messageId":"8d226216-9a80-471e-9d7b-3ca8d21c1e05@gmail.com","threadId":"61215","inReplyTo":"CAK_130T8sZUZAuvj4x7sB278kVL7ARaBv3Pg2djQB45O+7xKTg@mail.gmail.com","subject":"Re: Update message_advice_pull_before_push to mention how to push after rebasing","fromName":"Rubén Justo","fromEmail":"rjusto@gmail.com","sentAt":"2024-03-28T11:49:30Z","receivedAt":"2024-03-28T11:49:37Z","isPatch":false,"sender":{"key":"rjusto@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5685487?v=4"},"body":"On Thu, Mar 28, 2024 at 05:54:13PM +0800, zhang kai wrote:\n> Hi all,\n> \n> Our team uses git rebase a lot. A common hiccup we noticed during the\n> daily work is that new devs often didn't know how to push properly\n> after the rebase.\n> \n> When someone try to push to the remote after rebasing the branch, the\n> push would mostly fail with the message_advice_pull_before_push:\n> \n> > Updates were rejected because the tip of your current branch is behind\\n\" \"its remote counterpart. If you want to integrate the remote changes,\\n\" \"use 'git pull' before pushing again.\\n\" \"See the 'Note about fast-forwards' in 'git push --help' for details.\n> \n> However, in this situation, pull will \"invalid\" the rebasing. After\n> pull then push, devs often will be surprised by the merge/pull request\n> containing diffs that should not be in this branch. In this case, we\n> often should just do `git push --force-with-lease`.\n> \n> If we add a message like \"If you just rebased your branch, please\n> consider 'git push --force-with-lease'\" to the\n> message_adivce_pull_before_push, we may save devs some time figuring\n> out what's wrong with their branch.\n\nIt does sound sensible ...\n\n> If this is acceptable, we'd be\n> happy to prepare a patch.\n\n... but you should better expect acceptance after sending a concrete\nseries that makes the objective clear ;)\n\nI see that we are using, in builtin/push.c, the form:\n\n\tif (advice_enabled(XXX))\n\t\tadvise(YYY)\n\nIt would be well received, I think, if your proposal includes a change\nfor that, to start using the now preferred advise_if_enabled() mechanism.\n\nOf course, this is entirely optional and does not need to be done in the\ncontext of this hypothetical series.\n\nThanks.\n"},{"id":"491753","messageId":"xmqqo7aywfc5.fsf@gitster.g","threadId":"61215","inReplyTo":"CAK_130T8sZUZAuvj4x7sB278kVL7ARaBv3Pg2djQB45O+7xKTg@mail.gmail.com","subject":"Re: Update message_advice_pull_before_push to mention how to push after rebasing","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-03-28T15:23:06Z","receivedAt":"2024-03-28T15:23:12Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"zhang kai <kylerzhang11@gmail.com> writes:\n\n> Hi all,\n>\n> Our team uses git rebase a lot. A common hiccup we noticed during the\n> daily work is that new devs often didn't know how to push properly\n> after the rebase.\n>\n> When someone try to push to the remote after rebasing the branch, the\n> push would mostly fail with the message_advice_pull_before_push:\n>\n>> Updates were rejected because the tip of your current branch is behind\\n\" \"its remote counterpart. If you want to integrate the remote changes,\\n\" \"use 'git pull' before pushing again.\\n\" \"See the 'Note about fast-forwards' in 'git push --help' for details.\n>\n> However, in this situation, pull will \"invalid\" the rebasing. After\n> pull then push, devs often will be surprised by the merge/pull request\n> containing diffs that should not be in this branch. In this case, we\n> often should just do `git push --force-with-lease`.\n\nUse of --force-with-lease without specifying exactly what commit to\nexpect there is not a good hygiene, but when you rebase your topic\nbranch on the updated upstream, you are already committed to force\nupdate your published topic branch.  So \"your push does not\nfast-forward; pull first before pushing again\" is not sufficient.\nIf you know your push does not fast-forward, and if you want to\nforce push, then you should not pull first.\n\n> If we add a message like \"If you just rebased your branch, please\n> consider 'git push --force-with-lease'\" to the\n> message_adivce_pull_before_push, we may save devs some time figuring\n> out what's wrong with their branch.\n\nI am not sure if that is a good idea in general, though.  That \"if\nyou just rebased\" applies only to the case where you rebased your\ntopic branch.  If you forked to work on topic from the upstream's\nprimary integration branch, worked on that topic, and then rebased\nyour topic on top of the updated upstream integration branch (which\ncontains new work from others since you forked and while you were\nworking on that topic), you do not want to force.  force-with-lease\nmay help you avoid overwriting and discarding others work, but the\nonly sensible next step in such a case is to pull-rebase again,\nwhich will rebase your work on the topic to build on these recent\nwork from others.\n\nSo, I dunno.\n"},{"id":"491764","messageId":"CAK_130RadXce-_PwnZTzJ6qmr3m=OXd2M9bCj2gggM49RxL9=g@mail.gmail.com","threadId":"61215","inReplyTo":"xmqqo7aywfc5.fsf@gitster.g","subject":"Re: Update message_advice_pull_before_push to mention how to push after rebasing","fromName":"zhang kai","fromEmail":"kylerzhang11@gmail.com","sentAt":"2024-03-28T17:19:23Z","receivedAt":"2024-03-28T17:19:34Z","isPatch":false,"sender":{"key":"kylerzhang11@gmail.com","avatar":null},"body":"> I am not sure if that is a good idea in general, though.  That \"if\n> you just rebased\" applies only to the case where you rebased your\n> topic branch.  If you forked to work on topic from the upstream's\n> primary integration branch, worked on that topic, and then rebased\n> your topic on top of the updated upstream integration branch (which\n> contains new work from others since you forked and while you were\n> working on that topic), you do not want to force.  force-with-lease\n> may help you avoid overwriting and discarding others work, but the\n> only sensible next step in such a case is to pull-rebase again,\n> which will rebase your work on the topic to build on these recent\n> work from others.\n\nIndeed, there may be more complicated cases. I think the key is\nwhether the tip of your current branch is really behind its remote\ncounterpart.\nHow about we update the advice like this:\n\nUpdates were rejected because the tip of your current branch is behind\nits remote counterpart. If you want to integrate the remote changes,\nuse 'git pull' before pushing again. If this is not the case, you may consider\n`git push --force-with-lease`.\nSee the 'Note about fast-forwards' in 'git push --help' for details.\n\nThen, we add a more detailed explanation in the ‘git push —help’ message.\n"},{"id":"491768","messageId":"xmqq5xx6uume.fsf@gitster.g","threadId":"61215","inReplyTo":"CAK_130RadXce-_PwnZTzJ6qmr3m=OXd2M9bCj2gggM49RxL9=g@mail.gmail.com","subject":"Re: Update message_advice_pull_before_push to mention how to push after rebasing","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-03-28T17:35:53Z","receivedAt":"2024-03-28T17:36:04Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"zhang kai <kylerzhang11@gmail.com> writes:\n\n> Updates were rejected because the tip of your current branch is behind\n> its remote counterpart. If you want to integrate the remote changes,\n> use 'git pull' before pushing again. If this is not the case, you may consider\n> `git push --force-with-lease`.\n> See the 'Note about fast-forwards' in 'git push --help' for details.\n\nTrue, but isn't that a slipperly slope to cram more and more of the\nmaterial from the manual into the \"hint\" that is supposed to be\nshort, helpful and not so obnoxious?  Perhaps removing \"pull again\nbefore you push\", and saying \"updates were rejected because X; see\nthe note about fast-forwards in the manual\" and nothing else would\nbe an improvement?\n\nThanks.\n"},{"id":"491818","messageId":"CAK_130R-AM6ZKJe52hc_XaLwi++VKm_bW5Ar8m8Yo7JLUnt9Yw@mail.gmail.com","threadId":"61215","inReplyTo":"xmqq5xx6uume.fsf@gitster.g","subject":"Re: Update message_advice_pull_before_push to mention how to push after rebasing","fromName":"zhang kai","fromEmail":"kylerzhang11@gmail.com","sentAt":"2024-03-29T07:41:03Z","receivedAt":"2024-03-29T07:41:15Z","isPatch":false,"sender":{"key":"kylerzhang11@gmail.com","avatar":null},"body":"> True, but isn't that a slipperly slope to cram more and more of the\n> material from the manual into the \"hint\" that is supposed to be\n> short, helpful and not so obnoxious?  Perhaps removing \"pull again\n> before you push\", and saying \"updates were rejected because X; see\n> the note about fast-forwards in the manual\" and nothing else would\n> be an improvement?\n\nI agree. Removing \"pull again before you push\" is definitely an\nimprovement for our workflow. But I know some teams don't use rebase\nat all, so it may not be ideal for them.\n"}]}