git push 到远程分支
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6279082/
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 to remote branch
提问by Rubyalto
Folks,
各位,
I had cloned a repo. I created a branch out of it to work on a feature by issuing the following command:
我克隆了一个回购。我通过发出以下命令,从中创建了一个分支来处理某个功能:
git branch fix78
git branch fix78
then I worked on that branch by
然后我在那个分支上工作
git checkout fix78
git checkout fix78
I continued to make commits to this local branch. Now I wanted to push this to the repo and hence I issued the following command:
我继续向这个本地分支提交。现在我想把它推送到 repo,因此我发出了以下命令:
git push origin master:fix78
git push origin master:fix78
I viewed the repo from a web browser and saw that a new branch called fix78 was created on the repo. But it did not have any of my commits that I had made.
我从 Web 浏览器查看了 repo,看到在 repo 上创建了一个名为 fix78 的新分支。但它没有我所做的任何承诺。
What am I doing wrong here? This is what I am trying to achieve:
我在这里做错了什么?这就是我想要实现的目标:
There is a repo(master(trunk in the SVN lingo)), now when I am working on a feature I want to create a local branch of it and then I also want to check in this branch to the repo(so that other team members can see what I am working on), then I want my local branch to be in sync with this remote branch that I create.
有一个 repo(master(trunk in the SVN lingo)),现在当我在处理一个特性时,我想创建它的本地分支,然后我也想将此分支签入到 repo(以便其他团队成员可以看到我在做什么),然后我希望我的本地分支与我创建的这个远程分支同步。
Any help/feedback would be totally awesome.
任何帮助/反馈都非常棒。
Thanks.
谢谢。
回答by rlc
git push origin master:fix78
pushes the local master to a remote branch called fix78. You wanted to push the local branch fix78, which has the same syntax but without the master:
git push origin master:fix78
将本地 master 推送到名为 fix78 的远程分支。您想推送本地分支 fix78,它具有相同的语法但没有master:
You can fix it by doing git push origin :fix78
to delete the remote branch and then git push origin fix78
to push your local branch to the remote repo.
您可以通过git push origin :fix78
删除远程分支然后git push origin fix78
将本地分支推送到远程仓库来修复它。
回答by Adam Dymitruk
The push command has the form of
push 命令的形式为
git push remote_name source_ref:destination_ref
All you need to do to correct your error is
你需要做的就是纠正你的错误
git push origin +fix78:fix78
The plus indicates that you don't care about that branch potentially losing history as the previous push was an error.
加号表示您不关心该分支可能会丢失历史记录,因为之前的推送是错误的。
Alternate syntax is
替代语法是
git push -f origin fix78
if you omit the destination, it's implied that it's the same name. If tracking is set up to a particular branch on the remote it will go to that one. Deleting branches has 2 syntaxes, the old:
如果省略目的地,则暗示它是同名的。如果跟踪设置到远程上的特定分支,它将转到该分支。删除分支有两种语法,旧的:
git push -f origin :fix78
and
和
git push --delete origin fix78
The first is read as "push nothing into fix78" which deletes it.
第一个读作“不将任何内容推入 fix78”将其删除。
One trick is that if you specify .
as the remote name, it implies the current repo as the remote. This is useful for updating a local branch without having to check it out:
一个技巧是,如果您指定.
为远程名称,则表示当前存储库为远程。这对于更新本地分支而无需检查它很有用:
git push . origin/master:master
will update master without having to checkout master.
将更新 master 而无需结帐 master。
Hope this helps
希望这可以帮助