为什么git会推动这个git push中的两个分支? [英] Why is git pushing to two branches in this git push?
问题描述
什么可能会导致'git push'尝试投入两个分支?我有我自己的分支,我正在工作,这是共享回购...和主分支。现在我只是想推到我的个人分支,经历的很好,但它也试图推动主人并被拒绝。看起来像这样:
foo $ git push
计数对象:38,完成。
使用2个线程的增量压缩。
压缩对象:100%(19/19),完成。
写作对象:完成100%(21/21),9.73 KiB。
总计21(增量14),重用0(增量0)
到ssh://example.com/project.git
8184634..86b621e mybranch - > mybranch
! [被拒绝] master - > master(非快速转发)
错误:无法将某些引用推送到'ssh://example.com/project.git'
我的配置如下所示:
remote.origin.url = ssh:/ /example.com/project.git
remote.origin.fetch = + refs / heads / *:refs / remotes / origin / *
branch.master.remote = origin
branch.master .merge = refs / heads / master
branch.mybranch.remote = origin
branch.mybranch.merge = refs / heads / mybranch
Esko指出,它推动了两者,因为它们在我的配置中。如果我想推向两者,而不是同时进行呢?当我将mybranch检出并且我推动时,我显然意味着推动mybranch而不是主人。有时候我会结账主,编辑代码,并且还想提交/推送。是否有共存的方式?
使用 git push
没有任何参数,它会推送具有相同名称的相应远程分支的所有本地分支。由于您的本地存储库具有分支 master
和 mybranch
,并且远程存储库还有分支 master
和 mybranch
,那么Git会推送它们两个。
如果你想只推送一个分支,你可以明确地告诉Git你想推哪个分支: git push origin mybranch
如果你想推动主人,你可以先从主人拉出来解决这个错误。 Git抱怨合并是非快速前进,因为有人从你上次从主服务器上拉下来以后向主人推送了一个提交。
What would possibly cause a 'git push' to try and commit to two branches? I have my own branch I'm working on, which is on the shared repo... and a master branch. Right now I just wanted to push to my personal branch which went through just fine, but it also tried to push to master and got rejected. Looked something like this:
foo$ git push
Counting objects: 38, done.
Delta compression using 2 threads.
Compressing objects: 100% (19/19), done.
Writing objects: 100% (21/21), 9.73 KiB, done.
Total 21 (delta 14), reused 0 (delta 0)
To ssh://example.com/project.git
8184634..86b621e mybranch -> mybranch
! [rejected] master -> master (non-fast forward)
error: failed to push some refs to 'ssh://example.com/project.git'
My config looks like this:
remote.origin.url=ssh://example.com/project.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master
branch.mybranch.remote=origin
branch.mybranch.merge=refs/heads/mybranch
Esko notes that it's pushing to both because they're in my config. What if I want to push to both, just not simultaneously? When I have mybranch checked out and I git push, I clearly mean to push mybranch and not master. There's times when I'll checkout master, edit code, and want to commit/push that also. Is there a way for both to co-exist?
When using git push
without any arguments, it will push all local branches that have a corresponding remote branch with the same name. Since your local repository has branches master
and mybranch
, and also the remote repository has branches master
and mybranch
, then Git will push both of them.
If you want to push only one branch, you can say to Git explicitly that which branch you want to push: git push origin mybranch
If you want to push master, you can fix that error by first pulling from master. Git complains about the merge being non-fast forward, because somebody else has pushed a commit to master since the last time that you pulled from master.
这篇关于为什么git会推动这个git push中的两个分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!