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

Git

Git Problem Overview


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

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

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

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

But the next time I try git push it 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?

Update: ./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 HEAD the following line appeared in .git/config to [remote "origin"] section:

	push = HEAD

Update3:

$ 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.

Git Solutions


Solution 1 - Git

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.

Solution 2 - Git

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

Solution 3 - Git

You must specify which branch you are pushing to. git push would 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 origin master

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

Solution 4 - Git

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

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.

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

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 branch section in your git global config and you should be good to go.

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

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

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 push on master branch.

git remote show origin also shouldn't cause a warning anymore.

Solution 5 - Git

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

git remote -v

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

git remote rm origin

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

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

pull + push = FIXED

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionfiredevView Question on Stackoverflow
Solution 1 - GitPeter van der DoesView Answer on Stackoverflow
Solution 2 - GitmmullisView Answer on Stackoverflow
Solution 3 - GitredDragonzzView Answer on Stackoverflow
Solution 4 - GitjosephtingView Answer on Stackoverflow
Solution 5 - GitsuzumakesView Answer on Stackoverflow