git push vs git push origin <branchname>
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19312622/
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
git push vs git push origin <branchname>
提问by dhblah
I'm quite new to Git.
我对 Git 很陌生。
I'm creating a branch and then want to push it to origin
.
我正在创建一个分支,然后想将它推送到origin
.
I think that simply issuing git push
(while standing on my branch) should be sufficient.
我认为简单地发行git push
(站在我的分支上)就足够了。
Is it possible/reasonable to do that (by specifying push.default simple)?
这样做是否可能/合理(通过指定 push.default simple)?
回答by VonC
The first push should be a:
第一次推送应该是:
git push -u origin branchname
That would make sure:
这将确保:
- your local branch has a remote tracking branchof the same name referring an upstream branchin your remote repo '
origin
', - this is compliant with the default push policy '
simple
'
- 您的本地分支有一个同名的远程跟踪分支,指的是远程仓库“ ”中的上游分支
origin
, - 这符合默认推送策略“
simple
”
Any future git push will, with that default policy, only push the current branch, and only if that branch has an upstream branch with the same name.
that avoid pushing allmatching branches (previous default policy), where tons of test branches were pushed even though they aren't ready to be visible on the upstream repo.
任何未来的 git push 将使用该默认策略,仅推送当前分支,并且仅当该分支具有同名的上游分支时。
避免推送所有匹配的分支(以前的默认策略),其中推送了大量测试分支,即使它们还没有准备好在上游 repo上可见。
回答by vkulkarni
First, you need to create your branch locally
首先,您需要在本地创建您的分支
git checkout -b your_branch
After that, you can work locally in your branch, when you are ready to share the branch, push it. The next command push the branch to the remote repository origin and tracks it
之后,您可以在您的分支本地工作,当您准备好共享分支时,推送它。下一个命令将分支推送到远程存储库源并对其进行跟踪
git push -u origin your_branch
Your Teammates/colleagues can push to your branch by doing commits and then push explicitly
你的队友/同事可以通过提交然后明确推送到你的分支
... work ...
git commit
... work ...
git commit
git push origin HEAD:refs/heads/your_branch