How to remove remote origin/refs/heads/master
Asked Answered
C

3

22

Don't ask me how but I managed to get accidentally the following remote branches in a git repository:

$ git branch -r
  origin/HEAD -> origin/master
  origin/master
  origin/refs/heads/master

All are pointing to the same commit. How can I remove the unnecessary listing for origin/refs/heads/master?

I tried to do the following

$ git push origin :refs/heads/master
error: dst refspec refs/heads/master matches more than one.

But as shown, this gives an error.

Cardon answered 3/2, 2011 at 19:34 Comment(0)
C
20

The solution was to delete the branch refs/heads/refs/heads/master

git push origin :refs/heads/refs/heads/master
Cardon answered 7/2, 2011 at 10:45 Comment(0)
C
44

That's not actually a branch on the remote - it's just a local ref that claims to be representing something on the remote, just as origin/master represents the master branch on the remote. The full name of the ref is refs/remotes/origin/refs/heads/master. All you have to do to delete it is:

git branch -r -d origin/refs/heads/master

It's vaguely possible that you managed to push this as well (but you'd have had to try extra hard to do so). If you did, I'd simply listing the refs of origin:

git ls-remote origin

and then, if there's anything stupid there, using git push origin :<refname> to get rid of it.

P.S. If this doesn't do it for you, you're going to want to use git for-each-ref to see all of your refs, and possibly git ls-remote origin to see all the remote ones, and track down exactly which things don't belong, with their fully qualified refnames.

Cochran answered 3/2, 2011 at 20:12 Comment(2)
Hmm, it was origin/refs/heads/refs/heads/master and I deleted it with git push origin :refs/heads/refs/heads/masterCardon
@Peter: well, that is what I guessed in the first paragraph. I'm impressed that you managed to get it into the remote; it took me a bit to figure out how to do that myself! Glad you got it sorted out.Cochran
C
20

The solution was to delete the branch refs/heads/refs/heads/master

git push origin :refs/heads/refs/heads/master
Cardon answered 7/2, 2011 at 10:45 Comment(0)
K
5

It's

git branch -r -d origin/ref/heads/master

instead of

git branch -r -d origin/refs/heads/master 

in the code part to delete branch. There is difference in ref word in the code.

Knopp answered 17/3, 2012 at 6:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.