简体   繁体   中英

What would "git push --set-upstream master master" do?

Would this push to the master branch? It seems like it would likely do nothing and not work, unless you had set "master" as a shortname for a branch.

The git push command syntax is:

git push [options] [<repository> [<refspec>...]]

as you can see from the SYNOPSIS line in the documentation (I've shortened it here for explanatory purposes; the one in the documentation spells out all the options).

The square brackets indicate that something is optional, so both the <repository> and <refspec> arguments are optional, but you gave both here:

git push --set-upstream master master

Your list of options—which are of course optional—consists entirely of --set-upstream . The remaining words are master , which is the name of the repository, and master , which is the first (and only) refspec. (Had you listed more words that were not options, they would be additional refspecs.)

Your task is now to search downwards in the same documentation for the meaning of the <repository> and <refspec> parts. The documentation here is very long and rather ugly for historical reasons, so let's simplify it:

  • The repository argument should be the name of a remote .

  • The refspec argument should usually be the name of a branch.

Presumably, master is in fact the name of a branch. It's possible that you used:

git remote add

to create a remote named master as well, but that seems unlikely. If you did not do that, Git would try to treat master as a URL. Because Git extends the URL syntax, the result of treating master as a URL is to try to use master as a path , as if you'd typed in /home/bones225/repos/master or /Users/bones225/github.com/master or something.

If that path names a valid repository, that's the repository to which you'll git push . If not—as is likely—you'll simply get an error:

$ git push master master
fatal: 'master' does not appear to be a git repository
fatal: Could not read from remote repository.

(plus some additional information).

It seems like it would likely do nothing and not work, unless you had set "master" as a shortname for a branch.

I'm not sure what you mean by "shortname for a branch" (branches should already be short names), but you could also have discovered this by testing (presumably using a temporary repository with nothing valuable in it, for safety).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM