“git push”是否扩展到“git push origin master”



或者它是否扩展到git push origin <current-branch-name>

引用

  • http://git-scm.com/book/en/v2/Git-Basics-Working-with-Remotes
    • git push [remote-name] [branch-name]

TL;DR

默认情况下,git push会扩展到自 Git 2.0 年以来的git push origin <current-branch>或旧版本git push origin <all-matching-branches>

实际答案

有关git push的所有问题的答案都在 git push 的文档页面中:http://git-scm.com/docs/git-push

该页面的一个片段(我删除了无数选项,因为它们在问题中没有提到):

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

当命令行未指定使用 <repository> 参数推送的位置时,将参考当前分支branch.*.remote配置以确定推送位置。如果缺少配置,则默认为 origin

当命令行没有指定使用<refspec>...参数或--all--mirror--tags选项推送什么时,该命令通过查阅remote.*.push配置来查找默认<refspec>,如果未找到,则遵循push.default配置来决定推送什么(有关push.default的含义,请参阅git-config[1])。

由于Git 2.0 push.default的默认值是simple这意味着使用一些检查和条件推送当前分支,这些检查和条件可以使git在某些情况下拒绝push

Git 2.0之前,push.default的默认值曾经是matching这意味着在两端推送所有具有相同名称的分支。此模式还需要满足一些条件才能成功。

有关push.default的更多详细信息,请参阅git config的文档页面或在终端上键入git help config

是的,如果你是主版,它会扩展到git push origin master

如果您在分支上mybranch它会扩展到 git push origin mybranch

如果您从未推送过mybranch,则会出现以下消息:

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

然后你必须为第一个push执行一次git push --set-upstream origin mybranch,从那时起你可以做一个git push,它将扩展到git push origin mybranch

最新更新