我的 .git/config:
[remote "origin"]
url = git@github.com:nfpyfzyf/test.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
我本地的分支机构:
HEAD
|
F---G feature**current branch
/
C---D---E develop
/
A---B master
我现在在功能分支中,想推送到远程。当前命令是什么,是git push origin feature
吗?如果我执行 git push
会发生什么?
最佳答案
要推送特定分支,请运行 git push <remote> <branch>
.在您的情况下,您唯一定义的 Remote 是 origin
,并且您想推送您的 feature
分支,所以使得
$ git push origin feature
“Examples” section of the git push
documentation描述如果你运行 git push
会发生什么没有其他参数。
git push
Works like
git push <remote>
, where is the current branch’s remote (ororigin
, if no remote is configured for the current branch).
鉴于您问题中的配置,您的 feature
分支没有配置远程,所以上面的调用等同于下一个例子。
git push origin
Without additional configuration, works like
git push origin :
…
沿着菊花链,我们看到这等同于
git push origin :
Push “matching” branches to origin. See in the OPTIONS section above for a description of "matching" branches.
匹配分支的规则是
The special refspec
:
(or+:
to allow non-fast-forward updates) directsgit
to push “matching” branches: for every branch that exists on the local side, the remote side is updated if a branch of the same name already exists on the remote side. This is the default operation mode if no explicit refspec is found (that is neither on the command line nor in any Push line of the corresponding remotes file—see below) and nopush.default
configuration variable is set.
在您的情况下,唯一匹配的分支是 master
, 所以 git push
将推送该分支并退出。
关于git - git 如何将当前分支推送到另一个远程/源?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16166713/