简体   繁体   中英

Does `git push` expand to `git push origin master`?

Or does it expand to git push origin <current-branch-name> ?

References

TL;DR

By default, git push expands to git push origin <current-branch> since Git 2.0 or git push origin <all-matching-branches> for older versions.

The actual answer

The answers to all your questions regarding git push are in the documentation page of git push : http://git-scm.com/docs/git-push

A fragment from that page (I removed the myriad of options as they are not mentioned in the question) :

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

When the command line does not specify where to push with the <repository> argument, branch.*.remote configuration for the current branch is consulted to determine where to push. If the configuration is missing, it defaults to origin .

When the command line does not specify what to push with <refspec>... arguments or --all , --mirror , --tags options, the command finds the default <refspec> by consulting remote.*.push configuration, and if it is not found, honors push.default configuration to decide what to push (See git-config[1] for the meaning of push.default ).

Since Git 2.0 the default value of push.default is simple which means push current branch with some checks and conditions that can make git refuse to push in some situations.

Before Git 2.0 , the default value of push.default used to be matching which means push all branches having the same name on both ends . This mode also requires some conditions to be met in order to succeed.

For more details about push.default see the documentation page of git config or type git help config on your terminal.

Yes, it expands to git push origin master if you are on master.

If you are on a branch mybranch it expands to git push origin mybranch .

If you have never pushed mybranch , this message will appear:

fatal: The current branch mybranch has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin mybranch

Then you have to execute git push --set-upstream origin mybranch once for the first push , and from then on you can just do a git push which will expand to git push origin mybranch .

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