threads / discuss / 61215

Update message_advice_pull_before_push to mention how to push after rebasing

Subject: Update message_advice_pull_before_push to mention how to push after rebasing

## tl;dr

6 messages between Mar 28, 2024 and Mar 29, 2024.

replies: 5people: 3as markdown or json

zhang kai· Mar 28, 2024, 09:54 UTC · lore
Hi all,

Our team uses git rebase a lot. A common hiccup we noticed during the daily work is that new devs often didn't know how to push properly after the rebase.

When someone try to push to the remote after rebasing the branch, the push would mostly fail with the message_advice_pull_before_push:

> 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.

However, in this situation, pull will "invalid" the rebasing. After pull then push, devs often will be surprised by the merge/pull request containing diffs that should not be in this branch. In this case, we often should just do `git push --force-with-lease`.

If we add a message like "If you just rebased your branch, please consider 'git push --force-with-lease'" to the message_adivce_pull_before_push, we may save devs some time figuring out what's wrong with their branch. If this is acceptable, we'd be happy to prepare a patch.

Thanks, Kai

Rubén Justo· Mar 28, 2024, 11:49 UTC · re: zhang kai · lore

Re: Update message_advice_pull_before_push to mention how to push after rebasing

On Thu, Mar 28, 2024 at 05:54:13PM +0800, zhang kai wrote:
Show 20 quoted lines
> Hi all,
> 
> Our team uses git rebase a lot. A common hiccup we noticed during the
> daily work is that new devs often didn't know how to push properly
> after the rebase.
> 
> When someone try to push to the remote after rebasing the branch, the
> push would mostly fail with the message_advice_pull_before_push:
> 
> > 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.
> 
> However, in this situation, pull will "invalid" the rebasing. After
> pull then push, devs often will be surprised by the merge/pull request
> containing diffs that should not be in this branch. In this case, we
> often should just do `git push --force-with-lease`.
> 
> If we add a message like "If you just rebased your branch, please
> consider 'git push --force-with-lease'" to the
> message_adivce_pull_before_push, we may save devs some time figuring
> out what's wrong with their branch.
It does sound sensible ...
> If this is acceptable, we'd be
> happy to prepare a patch.

... but you should better expect acceptance after sending a concrete series that makes the objective clear ;)

I see that we are using, in builtin/push.c, the form:
	if (advice_enabled(XXX))
		advise(YYY)

It would be well received, I think, if your proposal includes a change for that, to start using the now preferred advise_if_enabled() mechanism.

Of course, this is entirely optional and does not need to be done in the context of this hypothetical series.

Thanks.
Junio C Hamano· Mar 28, 2024, 15:23 UTC · re: zhang kai · lore

Re: Update message_advice_pull_before_push to mention how to push after rebasing

zhang kai <kylerzhang11@gmail.com> writes:
Show 15 quoted lines
> Hi all,
>
> Our team uses git rebase a lot. A common hiccup we noticed during the
> daily work is that new devs often didn't know how to push properly
> after the rebase.
>
> When someone try to push to the remote after rebasing the branch, the
> push would mostly fail with the message_advice_pull_before_push:
>
>> 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.
>
> However, in this situation, pull will "invalid" the rebasing. After
> pull then push, devs often will be surprised by the merge/pull request
> containing diffs that should not be in this branch. In this case, we
> often should just do `git push --force-with-lease`.

Use of --force-with-lease without specifying exactly what commit to expect there is not a good hygiene, but when you rebase your topic branch on the updated upstream, you are already committed to force update your published topic branch. So "your push does not fast-forward; pull first before pushing again" is not sufficient. If you know your push does not fast-forward, and if you want to force push, then you should not pull first.

> If we add a message like "If you just rebased your branch, please
> consider 'git push --force-with-lease'" to the
> message_adivce_pull_before_push, we may save devs some time figuring
> out what's wrong with their branch.

I am not sure if that is a good idea in general, though. That "if you just rebased" applies only to the case where you rebased your topic branch. If you forked to work on topic from the upstream's primary integration branch, worked on that topic, and then rebased your topic on top of the updated upstream integration branch (which contains new work from others since you forked and while you were working on that topic), you do not want to force. force-with-lease may help you avoid overwriting and discarding others work, but the only sensible next step in such a case is to pull-rebase again, which will rebase your work on the topic to build on these recent work from others.

So, I dunno.
zhang kai· Mar 28, 2024, 17:19 UTC · re: Junio C Hamano · lore

Re: Update message_advice_pull_before_push to mention how to push after rebasing

Show 11 quoted lines
> I am not sure if that is a good idea in general, though.  That "if
> you just rebased" applies only to the case where you rebased your
> topic branch.  If you forked to work on topic from the upstream's
> primary integration branch, worked on that topic, and then rebased
> your topic on top of the updated upstream integration branch (which
> contains new work from others since you forked and while you were
> working on that topic), you do not want to force.  force-with-lease
> may help you avoid overwriting and discarding others work, but the
> only sensible next step in such a case is to pull-rebase again,
> which will rebase your work on the topic to build on these recent
> work from others.

Indeed, there may be more complicated cases. I think the key is whether the tip of your current branch is really behind its remote counterpart. How about we update the advice like this:

Updates were rejected because the tip of your current branch is behind its remote counterpart. If you want to integrate the remote changes, use 'git pull' before pushing again. If this is not the case, you may consider `git push --force-with-lease`. See the 'Note about fast-forwards' in 'git push --help' for details.

Then, we add a more detailed explanation in the ‘git push —help’ message.
Junio C Hamano· Mar 28, 2024, 17:35 UTC · re: zhang kai · lore

Re: Update message_advice_pull_before_push to mention how to push after rebasing

zhang kai <kylerzhang11@gmail.com> writes:
Show 5 quoted lines
> Updates were rejected because the tip of your current branch is behind
> its remote counterpart. If you want to integrate the remote changes,
> use 'git pull' before pushing again. If this is not the case, you may consider
> `git push --force-with-lease`.
> See the 'Note about fast-forwards' in 'git push --help' for details.

True, but isn't that a slipperly slope to cram more and more of the material from the manual into the "hint" that is supposed to be short, helpful and not so obnoxious? Perhaps removing "pull again before you push", and saying "updates were rejected because X; see the note about fast-forwards in the manual" and nothing else would be an improvement?

Thanks.
zhang kai· Mar 29, 2024, 07:41 UTC · re: Junio C Hamano · lore

Re: Update message_advice_pull_before_push to mention how to push after rebasing

Show 6 quoted lines
> True, but isn't that a slipperly slope to cram more and more of the
> material from the manual into the "hint" that is supposed to be
> short, helpful and not so obnoxious?  Perhaps removing "pull again
> before you push", and saying "updates were rejected because X; see
> the note about fast-forwards in the manual" and nothing else would
> be an improvement?

I agree. Removing "pull again before you push" is definitely an improvement for our workflow. But I know some teams don't use rebase at all, so it may not be ideal for them.

← back to recent threads