git/list[1] front-page[2] threads[3] people[4] search[5] about
 

git-push branch confusion caused by user mistake

From
Phil Hord <phil.hord@gmail.com>
Date
Mar 10, 2017, 21:44 UTC
Message-ID
<CABURp0pf=4BE=E7qeOmYAcqJb=qDeGJ1EFyfCf+hDtKjjMD=ng@mail.gmail.com>
This week a user accidentally did this:
    $ git push origin origin/master
    Total 0 (delta 0), reused 0 (delta 0)
    To parent.git
     * [new branch]      origin/master -> origin/master

He saw his mistake when the "new branch" message appeared, but he was confused about how to fix it and worried he broke something.

It seems reasonable that git expanded the original args into this one:
    git push origin refs/remotes/origin/master

However, since the dest ref was not provided, it was assumed to be the same as the source ref, so it worked as if he typed this:

    git push origin refs/remotes/origin/master:refs/remotes/origin/master
Indeed, git ls-remote origin shows the result:
    $ git ls-remote origin
    d1ff1c9224ae5e58a7656fb9ecc95865d42ed71e HEAD
    d1ff1c9224ae5e58a7656fb9ecc95865d42ed71e refs/heads/master
    d1ff1c9224ae5e58a7656fb9ecc95865d42ed71e refs/remotes/origin/master
Also, I verified that this (otherwise valid) command has similar
unexpected results:
    $ git remote add other foo.git && git fetch other && git push
origin other/topic
    $ git ls-remote origin
    d1ff1c9224ae5e58a7656fb9ecc95865d42ed71e HEAD
    d1ff1c9224ae5e58a7656fb9ecc95865d42ed71e refs/heads/master
    d1ff1c9224ae5e58a7656fb9ecc95865d42ed71e refs/remotes/origin/master
    d1ff1c9224ae5e58a7656fb9ecc95865d42ed71e refs/remotes/other/topic

I think git should be smarter about deducing the dest ref from the source ref if the source ref is in refs/remotes, but I'm not sure how far to take it. It feels like we should translate refspecs something like this for push:

    origin/master
        => refs/remotes/origin/master:refs/heads/master
    refs/remotes/origin/master
         => refs/remotes/origin/master:refs/heads/master
    origin/master:origin/master
         => refs/remotes/origin/master:refs/heads/origin/master
    master:refs/remotes/origin/master
         => refs/heads/master:refs/remotes/origin/master

That is, we should not infer a remote refspec of "refs/remotes/*"; we should only get there if "refs/remotes" was given explicitly by the user.

Does this seem reasonable?  I can try to work up a patch if so.
Next: Junio C Hamano
Message 1 of 5 in “git-push branch confusion caused by user mistake”
  1. Phil HordMar 10, 2017
  2. Junio C HamanoMar 10, 2017
  3. Jacob KellerMar 13, 2017
  4. Phil HordMar 13, 2017
  5. Jakub NarębskiMar 11, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.