是什么原因会导致'git push'尝试提交到两个分支?我正在自己的分支上工作,该分支位于共享存储库中...以及一个主分支。现在我只想推送到我的个人分支,这也成功了,但它还尝试推送到主分支并被拒绝了。看起来像这样:
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'
我的配置看起来像这样:
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并且使用git push时,我显然是要推送mybranch而不是master。有时我会检出master,编辑代码,并想要提交/推送那个分支。有没有一种方法让它们共存?
git push
,同时Git会拒绝推送并在另外两个分支上出现“[rejected]”和“failed to push some refs”的提示)。 - Ben Klein