git 如何将其他分支推送到远程/源?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16166713/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How git push other branch to remote/origin?
提问by nfpyfzyf
My .git/config:
我的.git/config:
[remote "origin"]
url = [email protected]:nfpyfzyf/test.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
My local branches:
我当地的分支机构:
HEAD
|
F---G feature**current branch
/
C---D---E develop
/
A---B master
I'm now in feature branch, and want to push to remote. What is the current command, is itgit push origin feature
? What will happen if I do git push
?
我现在在功能分支,想推送到远程。当前的命令是什么,是git push origin feature
吗?如果我这样做会发生什么git push
?
回答by Greg Bacon
To push a specific branch, run git push <remote> <branch>
. In your case, your only defined remote is origin
, and you want to push your feature
branch, so that makes
要推送特定分支,请运行git push <remote> <branch>
. 在您的情况下,您唯一定义的遥控器是origin
,并且您想推送您的feature
分支,这样就可以
$ git push origin feature
The “Examples” section of the git push
documentationdescribes what happens if you run git push
with no other arguments.
文档的“示例”部分git push
描述了如果您在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).
git push
就像
git push <remote>
,当前分支的远程在哪里(或者origin
,如果没有为当前分支配置远程)。
Given the configuration in your question, your feature
branch does not have a remote configured, so the above invocation is equivalent to the next example.
鉴于您问题中的配置,您的feature
分支没有配置远程,因此上述调用等效于下一个示例。
git push origin
Without additional configuration, works like
git push origin :
…
git push origin
没有额外的配置,就像
git push origin :
……
Following the daisy chain, we see that this is equivalent to
沿着菊花链,我们看到这相当于
git push origin :
Push “matching” branches to origin. See in the OPTIONSsection above for a description of "matching" branches.
git push origin :
将“匹配”分支推送到原点。有关“匹配”分支的描述,请参见上面的OPTIONS部分。
The rules for matching branches are
匹配分支的规则是
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.
特殊的 refspec
:
(或+:
允许非快进更新)指示git
推送“匹配”分支:对于本地端存在的每个分支,如果远程端已经存在同名分支,则更新远程端. 如果未找到明确的 refspec(即既不在命令行上也不在相应远程文件的任何 Push 行中,见下文)并且未push.default
设置配置变量,则这是默认操作模式。
In your case, the only matching branch is master
, so git push
will push that branch and exit.
在您的情况下,唯一匹配的分支是master
,因此git push
将推动该分支并退出。
回答by Patrick B.
Yes git push origin feature
is the right and explicit command.
Yesgit push origin feature
是正确且明确的命令。
What happens when you do git push
without arguments is influenced by your configuration. The configuration variable push.default
tells git what to do in this case. Check the man-page (git config --help
and search for push.default
) for more information. Just so much, there are several possibilities: nothing
, matching
, upstream
, simple
and current
.
git push
没有参数时会发生什么会受到您的配置的影响。配置变量push.default
告诉 git 在这种情况下要做什么。查看手册页(git config --help
并搜索push.default
)以获取更多信息。只是这么多,有几种可能:nothing
,matching
,upstream
,simple
和current
。
Also What is the difference between git push.default=current and push.default=upstream?can help.
另外git push.default=current 和 push.default=upstream 有什么区别?可以帮助。
回答by 1615903
git push origin feature
is correct. If you do just git push
it will probably say something like this:
git push origin feature
是正确的。如果你这样做,git push
它可能会说这样的话:
fatal: The current branch feature has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin feature
After you have used the --set-upstream
(or just -u), simple git push
will work
使用--set-upstream
(或仅使用 -u)后, simplegit push
将起作用
回答by alexclooze
If you're working with git-flowyou can use
如果您正在使用git-flow,则可以使用
git flow feature publish $FEATURE
to push the branch to your remote and create it remote.
将分支推送到您的远程并创建远程。
It's equal to do a simple
等于做一个简单的
git push origin $FEATURE
If you're simply doing a git push
it depends on your configuration what happens - in my configuration it pushes all remotely existing branches.
如果你只是做一个git push
它取决于你的配置会发生什么 - 在我的配置中它推送所有远程现有的分支。
回答by John Szakmeister
git push origin $FEATURE
is certainly correct, and will get you what you want. However, I often use:
git push origin $FEATURE
肯定是正确的,会得到你想要的。但是,我经常使用:
git push -u origin HEAD
This will push up my current branch, using the branch name, so I don't have to type it out explicitly on the command line. As mentioned in one of the other answers, -u
will set the upstream so that a plain git push
will work in the future.
这将使用分支名称推送我当前的分支,因此我不必在命令行上明确键入它。如其他答案之一所述,-u
将设置上游,以便平原git push
在未来工作。