Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove remote origin/refs/heads/master

Tags:

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.

like image 274
Peter Smit Avatar asked Feb 03 '11 19:02

Peter Smit


People also ask

How do I get rid of origin master remote?

To delete a remote branch, you can't use the git branch command. Instead, use the git push command with --delete flag, followed by the name of the branch you want to delete. You also need to specify the remote name ( origin in this case) after git push .

How do I remove a remote reference in git?

You can use the prune subcommand of git-remote for cleaning obsolete remote-tracking branches. Alternatively, you can use the get-fetch command with the --prune option to remove any remote-tracking references that no longer exist on the remote. That's all about deleting remote-tracking branches in Git.

What is git refs remotes origin head?

origin/HEAD is a local ref representing a local copy of the HEAD in the remote repository. (Its full name is refs/remotes/origin/HEAD.)


1 Answers

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.

like image 53
Cascabel Avatar answered Sep 22 '22 04:09

Cascabel