24

Another issue with git 1.8:

$ git push
error: dst ref refs/heads/master receives from more than one src.
error: failed to push some refs to 'gitosis@xxx.xx:xxx.git'

Suggestions? It was working before upgrading to 1.8.

$ git remote -v
origin  gitosis@xxx.xx:xxx.git (fetch)
origin  gitosis@xxx.xx:xxx.git (push)

After googling around I tried this first:

$ git push origin :refs/heads/refs/heads/master
remote: warning: Allowing deletion of corrupt ref.
To gitosis@xxx.xx:xxx.git
 - [deleted]         refs/heads/master

No idea what is that and why it was corrupt.

$ git pull
Already up-to-date.

$ git push
error: dst ref refs/heads/master receives from more than one src.
error: failed to push some refs to 'gitosis@xxx.xx:xxx.git'

Still not working, but origin master did work at least:

$ git push origin master
Counting objects: 42, done.
To gitosis@xxx.xx:xxx.git
3e3fc87..6e11d2a  master -> master

Okay, that kind of fixed it but what was the cause of the issue to begin with? Why origin/master suddenly got corrupted? What did I do with git push origin :refs/heads/refs/heads/master ?

.git/config:

[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = false
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = gitosis@xxx.xx:xx.git
push = HEAD
[branch "master"]
remote = origin
merge = refs/heads/master

ls .git/refs/remotes/origin:

HEAD    master  refs

In the end, now I have to do git push origin master every time. And the most annoying is that some repos work with git push, but on the most of them I got to add origin master but I don't understand why, and it can't be that I am alone having this problem.

firedev
  • 20,898
  • 20
  • 64
  • 94
  • Can you show the contents of your `.git/config` sections `[remote "origin"]` and `[branch "master"]`? Also, `ls .git/refs/remotes/origin`. – Brian Campbell Nov 14 '12 at 05:41
  • Here you go, but that is after I have 'fixed' it – firedev Nov 16 '12 at 11:11
  • I’m having the same problem except I never had refs/heads/refs/heads/ anywhere (looked in both .git/ and the server sides). I do have these in the global config as suggested to me: push.default=matching remote.origin.push=HEAD – mirabilos Aug 08 '13 at 12:49

5 Answers5

30

Another way to get this error is if you accidentally type in the name of the branch you are trying to push twice, i.e.:

git push master otherBranch master moreBranches

Yields this error. Fix is obvious once you're aware you've done it:

git push master otherBranch moreBranches
jcw
  • 5,132
  • 7
  • 45
  • 54
5

in my case I had a space in branch name:

git push origin 353-applyPermissions :353-applyPermissions

returns > error: dst ref refs/heads/353-applyPermissions receives from more than one src. but this one works:

git push origin 353-applyPermissions:353-applyPermissions
ShSehati
  • 508
  • 5
  • 7
4

It looks like you have an extra copy of your refs tree within refs/remotes/origin. Notice how within refs/remotes/origin, you have an extra refs directory? I don't know how this got there, but it's probably what is causing your problems. Due to the way Git handles abbreviations of refs (allowing you to drop the prefix, using only the suffix like origin/master), it is probably getting confused by having both refs/remotes/origin/master and refs/remotes/refs/remotes/origin/master.

I don't know how it got into this state; possibly a bug in a Git tool, possibly a typo that you made at some point. You fixed half of the problem by deleting the remote branch that was tracking this duplicate branch. I would be willing to bet you can fix the other half of the problem, and be able to do git push again, if you delete the refs/remotes/origin/refs directory.

Brian Campbell
  • 322,767
  • 57
  • 360
  • 340
  • Now I have made some changes and I have same problem again. – firedev Nov 19 '12 at 06:01
  • @Nick What changes did you make? Did you delete `.git/refs/remotes/origin/refs` like I mentioned? Remember that you will need to do an `rm -r` on it, as it's a directory and you want to delete all of its subdirectories. – Brian Campbell Nov 19 '12 at 06:22
  • I mean I have changed some code and wanted to push. Even `rm -r` is not helping, but I can push with git `push origin master`: `$ rm -r .git/refs/remotes/origin/refs/ $ git push error: dst ref refs/heads/master receives from more than one src. error: failed to push some refs to 'gitosis@xxx.xx:xx.git'` – firedev Nov 21 '12 at 17:30
0

Following what is explained in this git old patch (2007!)

Some refs go stale, e.g. when the forkee rebased and lost some objects needed by the fork.
The quick & dirty way to deal with those refs is to delete them and push them again.

However, git-push first would first fetch the current commit name for the ref, would receive a null sha1 since the ref does not point to a valid object, then tell receive-pack that it should delete the ref with this commit name.
delete_ref() would be subsequently be called, and check that resolve_ref() (which does not check for validity of the object) returns the same commit name. Which would fail.

refs/heads/refs/heads/master looks like a branch improperly named "refs/heads/master" (using namespaces for defining hierachical branch name), and points to nothing.
Deleting it was the right move.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I don't understand - I maybe had a couple of branches but I simply commit to my own repository, working alone on the project. Is this some kind of 1.8 transitioning bug? – firedev Nov 16 '12 at 11:12
  • @Nick no, I suppose it was more an incorrect state within the remote repo, which you pulled, and which introduced the incorrect branch name '`refs/heads/master`'. Hence the issue on the next push. – VonC Nov 16 '12 at 11:30
  • Few days later I made some changes, and I can't push again. – firedev Nov 19 '12 at 06:01
0

In my case I had a tag with same name as the branch name. rename branch name and works.

Dushmantha
  • 2,911
  • 1
  • 14
  • 21