[PATCH] push: mention "git pull" in error message for non-fast forwards

Subsystems: the rest

DORMANTno replies

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

[PATCH] push: mention "git pull" in error message for non-fast forwards

From: Matthieu Moy <hidden>
Date: 2016-06-15 22:49:14

The message remains fuzzy to include "git pull", "git pull --rebase" and
others, but directs the user to the simplest solution in the vast
majority of cases.

Signed-off-by: Matthieu Moy <redacted>
---
When the message was added, it was decided explicitely not to say
explicitely "use git pull", first because there are other ways to
merge, and then to encourage the users to read the docs.

After a few months of teaching newbies/students to use Git, the
question "it doesn't want to push, what shall I do" still comes in the
top questions asked. Each time I've been asked, the newbie's face was
enlightened by hearing just the word "pull".

So I guess those few extra characters in the error message would save
me a lot of time ;-).

 builtin/push.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/builtin/push.c b/builtin/push.c
index f4358b9..69bc2f2 100644
--- a/builtin/push.c
+++ b/builtin/push.c
@@ -130,8 +130,8 @@ static int push_with_options(struct transport *transport, int flags)
 
 	if (nonfastforward && advice_push_nonfastforward) {
 		fprintf(stderr, "To prevent you from losing history, non-fast-forward updates were rejected\n"
-				"Merge the remote changes before pushing again.  See the 'Note about\n"
-				"fast-forwards' section of 'git push --help' for details.\n");
+				"Merge the remote changes (e.g. 'git pull') before pushing again.  See the\n"
+				"'Note about fast-forwards' section of 'git push --help' for details.\n");
 	}
 
 	return 1;
-- 
1.7.2.1.28.g41d92

Re: [PATCH] push: mention "git pull" in error message for non-fast forwards

From: Jonathan Nieder <hidden>
Date: 2016-06-15 22:49:14

Hi Matthieu,

Matthieu Moy wrote:
quoted hunk
+++ b/builtin/push.c
@@ -130,8 +130,8 @@ static int push_with_options(struct transport *transport, int flags)
 
 	if (nonfastforward && advice_push_nonfastforward) {
 		fprintf(stderr, "To prevent you from losing history, non-fast-forward updates were rejected\n"
-				"Merge the remote changes before pushing again.  See the 'Note about\n"
-				"fast-forwards' section of 'git push --help' for details.\n");
+				"Merge the remote changes (e.g. 'git pull') before pushing again.  See the\n"
+				"'Note about fast-forwards' section of 'git push --help' for details.\n");
Your change is good.

This reminds me: sometimes people blindly “git pull” a rebased history
just to avoid a non-fast-forward push, and it irks me to no end.  So if
I were running the world, the output would be:

 error: rejected non-fast-forward push to '<url>'
 hint: To prevent you from losing history, non-fast-forward updates are
 hint: rejected by default.
 hint: See the 'Note about fast-forwards' section of 'git push --help'
 hint: for details.

and the relevant section of the manual would explain that

 1. if upstream is ahead of you, you may want to "git pull"

but

 2. if upstream rebased, you may want to "git pull --rebase", and
    yell at upstream a little while at it.

and

 3. if the history you are pushing to is both (1) known to be unstable
    and (2) wrong, you can override it with
    "git push <remote> +<refspec>".  Be sure to make sure the
    “[receive] denyNonFastForwards” setting is unset correctly in this
    case.

Jonathan
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help