6

In my project I've deleted all old branches that was hanging in git, but some branches I was not be able to remove:

$ git push origin :0.2.0.0
error: dst refspec 0.2.0.0 matches more than one.
error: failed to push some refs to 'ssh://git@<repo>.git'

I have few git repos and I have some old branches that was probably created by mistake. Those branches have the same name as a tag that was created and I'm not able to delete those branches.

Is there a way to delete those branches? It seems that the only command that you can find anywhere is git push origin :<branch> or git push -d origin <branch> and there are not distinction between branch and tag in those commands.

I have no idea how those branches were created, but I would like to get rid of them.

AD7six
  • 63,116
  • 12
  • 91
  • 123
jcubic
  • 61,973
  • 54
  • 229
  • 402

2 Answers2

8

dst refspec 0.2.0.0 matches more than one

Normally this isn't a problem but here git doesn't know which 0.2.0.0 this refers to, the solution is to be more explicit.

To delete the branch

To take care of the scenario in the question:

$ git push origin :refs/heads/0.2.0.0

To delete the tag

And for completeness, if it was the tag that was unwanted:

$ git push origin :refs/tags/0.2.0.0
AD7six
  • 63,116
  • 12
  • 91
  • 123
2

The exact meaning of the "refspec" argument to "git push" is quite complicated, and discussed at length in the git manual.

The most relevant part is this:

If doesn’t start with refs/ (e.g. refs/heads/master) we will try to infer where in refs/* on the destination <repository> it belongs based on the type of <src> being pushed and whether <dst> is ambiguous.

In other words, naming just the branch or tag is actually short-hand for naming a specific pointer in the "refs/" directory of the git repository.

To be more explicit, you can point to a specific entry in that directory:

  • Branches are stored in "refs/heads/", so "refs/heads/ABC" refers unambiguously to a branch
  • Tags are stored in "refs/tags/", so "refs/tags/ABC" refers unambiguously to a tag
  • Other refs can be used for other purposes; for instance, Github uses "refs/pull/123/head" and "refs/pull/123/merge" to refer to the current tip, and current merge result, of open Pull Request "123"
IMSoP
  • 89,526
  • 13
  • 117
  • 169