81

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 have tried to google but it seems that the problem is fairly new and I couldn't find any explanation for this behavior. Ideas?

Update: ./.git/config

[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url = gitosis@xxxx.xx: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.
MCI
  • 888
  • 1
  • 7
  • 13
firedev
  • 20,898
  • 20
  • 64
  • 94
  • git 2.0? The latest on git-scm.com is 1.8.0, I don't see anything in the github repo for git.. am I missing something? – Collin Oct 23 '12 at 12:49
  • Sorry, sorry, git 1.8.0, dunno why I wrote 2.0 – firedev Oct 23 '12 at 14:20
  • 1
    What does your `.git/config` file look like, especially the sections for this branch and your origin? – twalberg Oct 23 '12 at 14:25
  • this may be useful that you can use `git remote show origin` to check the local and remote branches status, or maybe `git branch --set-upstream-to` to reset. (according to **Git v1.8.0 Release Notes** "git branch --set-upstream" is deprecated and may be removed in a relatively distant future.) – xhlwill Dec 27 '12 at 10:51
  • Just by way of a note, the "./git/config" in your first update should be ".git/config". – KingAndy Jul 10 '13 at 09:33
  • I had a similar issue with our `LIVE` branch. When it was checked out I could not push it, if I was on `master` and did `git push --all` it worked. Editing the `.git/config` file by removing the duplicate entry for the branch that also was not listed by `git branch -vv` fixed the issue. – Thomas Jun 08 '17 at 07:58

5 Answers5

143

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.

Peter van der Does
  • 14,018
  • 4
  • 38
  • 42
  • Thanks, that helped but how? I see a new line in `[remote "origin"]` section in config: `push = HEAD`. And why it was saying that master has multiple upstream branches? – firedev Oct 25 '12 at 09:17
  • 2
    `git push` by default pushes all branches to the remote, by adding the configuration you tell git to only push the branch you are on. Maybe the error message you get is wrong, I mean that the branch name is wrong (master), maybe there are other branches that cause this problem. If you never had this problem with previous version of git, it could mean there is a regression problem. – Peter van der Does Oct 25 '12 at 11:07
  • Still months later I don't understand why this is happening, every now and then some repositories refuse to push. – firedev Feb 01 '13 at 03:47
  • @Nick What's the output of `git branch -vv` yes it's two v there. – Peter van der Does Feb 01 '13 at 13:48
  • Your master is behind the origin/master. What happens when you sync the local and remote master, `git merge origin/master`, remove the HEAD config `git config --unset remote.origin.push` and push again? – Peter van der Does Feb 02 '13 at 19:19
  • `Already up to date`, nothing, `fatal: The current branch master has multiple upstream branches, refusing to push.` – firedev Feb 03 '13 at 10:06
40

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.

Lucas Eduardo
  • 11,525
  • 5
  • 44
  • 49
mmullis
  • 500
  • 4
  • 4
  • 1
    I had this: `branch.master.remote=origin branch.master.merge=refs/heads/master` and indeed I had `branch "master"` in `~/.gitconfig`. Deleted it, will see how it goes, thanks! – firedev Aug 26 '13 at 07:50
  • 3
    Not sure how it occurred, but I had `branch.master.remote=origin` and `branch.master.merge=refs/heads/master` both _exactly_ repeated twice in `.git/config`... Removing the duplication resolved this issue. – Lucas Sep 20 '14 at 13:53
  • 2
    I ended up with a similar problem on one of my branches after renaming it locally and pushing the new name upstream. My .git/config file then had two entries. And like Lucas suggested deleting the duplicate resolves this. – Dev_Corps Dec 02 '16 at 08:33
10

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.

redDragonzz
  • 1,543
  • 2
  • 15
  • 33
  • But I did `git push origin master` even with `-u` key that should set `origin/master` as upstream for the `master` branch. No matter how I do it, the next time it refuses to `git push` – firedev Oct 23 '12 at 14:23
  • try git cloning again in a different or try Peter's suggestions below – redDragonzz Oct 23 '12 at 18:03
3

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.

josephting
  • 2,617
  • 2
  • 30
  • 36
1

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 git@github.com:yourname/yourrepo

pull + push = FIXED

suzumakes
  • 760
  • 3
  • 12