Git:fatal:当前分支master有多个上游分支,拒绝推送

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13030714/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 14:48:28  来源:igfitidea点击:

Git: fatal: The current branch master has multiple upstream branches, refusing to push

git

提问by firedev

I have this strange issue, whenever I do git pushit refuses to do anything:

我有这个奇怪的问题,每当我这样做时,git push它拒绝做任何事情:

fatal: The current branch master has multiple upstream branches, refusing to push.

fatal: The current branch master has multiple upstream branches, refusing to push.

When I do git push -u origin masterit seem to set it as a tracking branch:

当我这样做时,git push -u origin master它似乎将其设置为跟踪分支:

Branch master set up to track remote branch master from origin.

Branch master set up to track remote branch master from origin.

But the next time I try git pushit refuses to do this again. I tried to google but it seems the problem is fairly new and I couldn't find any explanation for this behaviour. Ideas?

但是下次我尝试时git push它拒绝再次这样做。我试图用谷歌搜索,但似乎这个问题很新,我找不到对这种行为的任何解释。想法?

Update:./git/config

更新:./git/config

[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url = [email protected]:milk.git
[branch "master"]
    remote = origin
    merge = refs/heads/master

Update2:Solved with git config remote.origin.push HEADthe following line appeared in .git/configto [remote "origin"]section:

UPDATE2:以解决git config remote.origin.push HEAD出现在下面一行.git/config[remote "origin"]部分:

    push = HEAD

Update3:

更新3:

$ git branch -vv
  billing      633c796 [origin/billing: behind 889] links
* master       1a0de50 [origin/master: ahead 1] more fixes
  new_master   3b880d7 [origin/new_master] branches diverged
  photo_stacks 29c8f0d [origin/photo_stacks] 1st try
  responsive   1dad980 [origin/responsive] update

$ git push
fatal: The current branch master has multiple upstream branches, refusing to push.

回答by Peter van der Does

You might want to do the following:

您可能想要执行以下操作:

git config remote.origin.push HEAD

Pushing without any arguments on a master branch can lead to your error message. I'm not sure if it's a regression problem, or if it's always been the case.

在 master 分支上不带任何参数推送可能会导致您的错误消息。我不确定这是回归问题,还是一直都是这样。

回答by mmullis

Run git config -land look to see if you have multiple lines containing branch.master* references The [branch "master"] section may be duplicated ~/.gitconfigand .git/config.Deleting the one in ~/.gitconfigfixed the mutiple upstream branch detection for me.

运行git config -l并查看是否有多行包含 branch.master* 引用 [branch "master"] 部分可能会重复~/.gitconfig.git/config.删除其中的一个,~/.gitconfig为我修复了多个上游分支检测。

回答by redDragonzz

You must specify which branch you are pushing to. git pushwould automatically attempt to push all the refs and tags that the local branches are tracking. It is possible that branches online at the server have moved forward. Therefore you might be ending up with this situation. You should simply use

您必须指定要推送到哪个分支。git push将自动尝试推送本地分支正在跟踪的所有引用和标签。服务器上的在线分支可能已经向前移动。因此,您可能会遇到这种情况。你应该简单地使用

git push origin master

And also to reconcile changes do a git pullThat will update your local refs with the one from the server.

并且为了协调更改做一个git pull这将使用来自服务器的引用更新您的本地引用。

回答by josephting

Most likely it's because there's 2 or more branch.master.remotein your git config. One from your global git config and another from your repo local git config.

很可能是因为branch.master.remote您的 git 配置中有 2 个或更多。一个来自您的全局 git 配置,另一个来自您的 repo 本地 git 配置。

When there is 2 of these specified in the git config, git plays it safe to not assume one or the other even though the latter defined should override the former.

当 git config 中指定了其中的 2 个时,git 会安全地不假设一个或另一个,即使后者定义应该覆盖前者。

Modern repositories you clone should include the config locally but your it's highly likely that your global git config has branch.master.remotedefined as well.

您克隆的现代存储库应该在本地包含配置,但您的全局 git 配置很可能也已branch.master.remote定义。

To check if you have it set in your global config, use:

要检查您是否在全局配置中设置了它,请使用:

git config --global --list | grep branch.master

You can remove or comment out branchsection in your git global config and you should be good to go.

您可以删除或注释掉branchgit 全局配置中的部分,您应该很高兴。

git config --global --remove-section branch.master

This will remove [branch "master"]section entirely.

这将[branch "master"]完全删除部分。

If you want to keep it in your global config just in case, you can rename it to some other branch that you probably won't use.

如果您想将其保留在全局配置中以防万一,您可以将其重命名为其他一些您可能不会使用的分支。

git config --global --rename-section branch.master branch.someothername

With this, you shouldn't get multiple upstream branches error when you do git pushon master branch.

有了这个,当你git push在 master 分支上做时,你不应该得到多个上游分支的错误。

git remote show originalso shouldn't cause a warning anymore.

git remote show origin也不应该再引起警告。

回答by suzumakes

Alright, after dealing with this twice with brand new repos I have an answer.

好吧,在用全新的 repos 处理了两次之后,我有了答案。

git remote -v

git远程 -v

git remote rm (everything other than origin if you've added any other remotes)

git remote rm (如果您添加了任何其他遥控器,则除原点之外的所有内容)

git remote rm origin

git远程rm原点

! warning: more than one branch.master.remote <-- this is good

!警告:不止一个 b​​ranch.master.remote <-- 这很好

git remote add origin [email protected]:yourname/yourrepo

git remote add origin [email protected]:yourname/yourrepo

pull + push = FIXED

拉 + 推 = 固定