git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Update message_advice_pull_before_push to mention how to push after rebasing
@ 2024-03-28  9:54 zhang kai
  2024-03-28 11:49 ` Rubén Justo
  2024-03-28 15:23 ` Junio C Hamano
  0 siblings, 2 replies; 6+ messages in thread
From: zhang kai @ 2024-03-28  9:54 UTC (permalink / raw)
  To: git

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Update message_advice_pull_before_push to mention how to push after rebasing
  2024-03-28  9:54 Update message_advice_pull_before_push to mention how to push after rebasing zhang kai
@ 2024-03-28 11:49 ` Rubén Justo
  2024-03-28 15:23 ` Junio C Hamano
  1 sibling, 0 replies; 6+ messages in thread
From: Rubén Justo @ 2024-03-28 11:49 UTC (permalink / raw)
  To: zhang kai, git

On Thu, Mar 28, 2024 at 05:54:13PM +0800, zhang kai wrote:
> 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.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Update message_advice_pull_before_push to mention how to push after rebasing
  2024-03-28  9:54 Update message_advice_pull_before_push to mention how to push after rebasing zhang kai
  2024-03-28 11:49 ` Rubén Justo
@ 2024-03-28 15:23 ` Junio C Hamano
  2024-03-28 17:19   ` zhang kai
  1 sibling, 1 reply; 6+ messages in thread
From: Junio C Hamano @ 2024-03-28 15:23 UTC (permalink / raw)
  To: zhang kai; +Cc: git

zhang kai <kylerzhang11@gmail.com> writes:

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Update message_advice_pull_before_push to mention how to push after rebasing
  2024-03-28 15:23 ` Junio C Hamano
@ 2024-03-28 17:19   ` zhang kai
  2024-03-28 17:35     ` Junio C Hamano
  0 siblings, 1 reply; 6+ messages in thread
From: zhang kai @ 2024-03-28 17:19 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Update message_advice_pull_before_push to mention how to push after rebasing
  2024-03-28 17:19   ` zhang kai
@ 2024-03-28 17:35     ` Junio C Hamano
  2024-03-29  7:41       ` zhang kai
  0 siblings, 1 reply; 6+ messages in thread
From: Junio C Hamano @ 2024-03-28 17:35 UTC (permalink / raw)
  To: zhang kai; +Cc: git

zhang kai <kylerzhang11@gmail.com> writes:

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Update message_advice_pull_before_push to mention how to push after rebasing
  2024-03-28 17:35     ` Junio C Hamano
@ 2024-03-29  7:41       ` zhang kai
  0 siblings, 0 replies; 6+ messages in thread
From: zhang kai @ 2024-03-29  7:41 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-03-29  7:41 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-28  9:54 Update message_advice_pull_before_push to mention how to push after rebasing zhang kai
2024-03-28 11:49 ` Rubén Justo
2024-03-28 15:23 ` Junio C Hamano
2024-03-28 17:19   ` zhang kai
2024-03-28 17:35     ` Junio C Hamano
2024-03-29  7:41       ` zhang kai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).