push: change needlessly ambiguous example in error
PATCH 1/1 push: change needlessly ambiguous example in error
Change an example push added in b55e677522 ("push: introduce new push.default mode "simple"", 2012-04-24) to always mean the same thing whether the current setting happens to be "simple" or not.
This error is only emitted under "simple", but message is explaining to the user that they can get two sorts of different behaviors by these two invocations.
Let's use "git push <remote> HEAD" which always means push the current branch name to that remote, instead of "git push <remote> <current-branch-name>" which will do that under "simple", but is not guaranteed to do under "upstream".
--- builtin/push.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
builtin/push.c +2 -2
@@ -173,10 +173,10 @@ static NORETURN int die_push_simple(struct branch *branch, struct remote *remote"\n" "To push to the branch of the same name on the remote, use\n" "\n" -" git push %s %s\n" +" git push %s HEAD\n" "%s"), remote->name, short_upstream, - remote->name, branch->name, advice_maybe); + remote->name, advice_maybe); } static const char message_detached_head_die[] =
Signature · 1 line
2.19.1.1182.g4ecb1133ce
Quoted 4 lines · Ævar Arnfjörð Bjarmason
Let's use "git push <remote> HEAD" which always means push the current branch name to that remote, instead of "git push <remote> <current-branch-name>" which will do that under "simple", but is not guaranteed to do under "upstream".
Probably a good idea indeed.
One potential objection though: I think many people know
git push origin master
(not that they necessarily understand it, but I've seen many people talking or asking questions about what "origin master" is)
This "git push origin HEAD" is IMHO less common. It may confuse users. Or users may learn it and be happy thanks to your message. I don't know.
Signature · 2 lines
Matthieu Moy https://matthieu-moy.fr/
Quoted 11 lines · Matthieu Moy
Quoted 4 lines · Ævar Arnfjörð Bjarmason
Let's use "git push <remote> HEAD" which always means push the current branch name to that remote, instead of "git push <remote> <current-branch-name>" which will do that under "simple", but is not guaranteed to do under "upstream".
Probably a good idea indeed.
One potential objection though: I think many people know
Quoted 7 lines
git push origin master
(not that they necessarily understand it, but I've seen many people talking or asking questions about what "origin master" is)
This "git push origin HEAD" is IMHO less common. It may confuse users. Or users may learn it and be happy thanks to your message. I don't know.
I was hoping for the latter. I'm slightly embarrassed to say that for the entire time I've been using git I've been doing:
# on branch 'topic'
git push origin topic:topicWhere 'topic' is a tracking branch of 'origin/master' (I use push.default=upstream). I only recently discovered that I could push to 'HEAD" to do the same thing. So one ulterior motive is to make that more prominent.
I was going to add a hint on such invocations saying "you can just use HEAD", but have not found the relevant code yet after some brief searching...
Quoted 6 lines · Ævar Arnfjörð Bjarmason
Quoted 2 lines
This "git push origin HEAD" is IMHO less common. It may confuse users. Or users may learn it and be happy thanks to your message. I don't know.
I was hoping for the latter. I'm slightly embarrassed to say that for the entire time I've been using git I've been doing:
Quoted 7 lines
# on branch 'topic' git push origin topic:topicWhere 'topic' is a tracking branch of 'origin/master' (I use push.default=upstream). I only recently discovered that I could push to 'HEAD" to do the same thing. So one ulterior motive is to make that more prominent.
Personally I do not think you should feel embarrassed at all. I didn't know it myself, and I do not recall designing such a behaviour, so I would not be surprised if it is merely what the code right now happens to do. FWIW, I would have expected that a "git push origin HEAD" when HEAD is a symref to a branch 'x' would behave as if "git push origin x" were given, going through the usual simple/upstream/matching etc. dance.
Do we consider the current behaviour useful? Is it documented already and widely known? If the answers are yes/no, of course we should document it, but if they are no/no, it may not be a bad idea to deprecate it and replace it with a saner version (i.e. deref HEAD to branch name and behave the same way as pushing that branch) over time.
Quoted 4 lines · Junio C Hamano
Quoted 4 lines
Where 'topic' is a tracking branch of 'origin/master' (I use push.default=upstream). I only recently discovered that I could push to 'HEAD" to do the same thing. So one ulterior motive is to make that more prominent.
[...]
Quoted 1 line
Do we consider the current behaviour useful? Is it documented
Yes, since 1750783 (Documentation: more git push examples, 2009-01-26).
It may be an accident that the doc says "to the same name on the remote." since it predates the introduction of push.default, but it does say so and it's the actual behavior.
Quoted 1 line
already and widely known?
https://stackoverflow.com/questions/14031970/git-push-current-branch-shortcut
458 votes for the answer suggesting it.
Signature · 2 lines
Matthieu Moy https://matthieu-moy.fr/
Quoted 15 lines · Matthieu Moy
Quoted 4 lines · Junio C Hamano
Quoted 4 lines
Where 'topic' is a tracking branch of 'origin/master' (I use push.default=upstream). I only recently discovered that I could push to 'HEAD" to do the same thing. So one ulterior motive is to make that more prominent.
[...]
Quoted 1 line
Do we consider the current behaviour useful? Is it documented
Yes, since 1750783 (Documentation: more git push examples, 2009-01-26).
It may be an accident that the doc says "to the same name on the remote." since it predates the introduction of push.default, but it does say so and it's the actual behavior.
Quoted 5 lines
Quoted 1 line
already and widely known?
https://stackoverflow.com/questions/14031970/git-push-current-branch-shortcut
458 votes for the answer suggesting it.
OK, that probably is good enough reason to keep the current behaviour and convince ourselves that there is nothing that needs to be done further on this topic.
Thanks.