Message ID | 20181113203909.30740-1-avarab@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | push: change needlessly ambiguous example in error | expand |
Ævar Arnfjörð Bjarmason" <avarab@gmail.com> wrote: > 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.
On Tue, Nov 13 2018, Matthieu Moy wrote: > Ævar Arnfjörð Bjarmason" <avarab@gmail.com> wrote: > >> 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. 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:topic 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. 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...
Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes: >> 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:topic > > 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. 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.
"Junio C Hamano" <gitster@pobox.com> wrote: > > 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. [...] > 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. > already and widely known? https://stackoverflow.com/questions/14031970/git-push-current-branch-shortcut 458 votes for the answer suggesting it.
Matthieu Moy <git@matthieu-moy.fr> writes: > "Junio C Hamano" <gitster@pobox.com> wrote: > >> > 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. > [...] >> 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. > >> 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.
diff --git a/builtin/push.c b/builtin/push.c index d09a42062c..8bb8a0849b 100644 --- a/builtin/push.c +++ b/builtin/push.c @@ -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[] =
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". Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> --- builtin/push.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)