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.
You should never name a tag and a branch the same name! It makes sense in a case like this to use naming conventions on the tags to keep from colliding on the branch names. Versus when we releasing code from the master branch. You can find the common parent in git using merge-base to do a Tag on code from the past.
The command to delete a local git branch can take one of two forms: git branch –delete old-branch. git branch -d old-branch.
Deleting a branch LOCALLY Delete a branch with git branch -d <branch> . The -d option will delete the branch only if it has already been pushed and merged with the remote branch. Use -D instead if you want to force the branch to be deleted, even if it hasn't been pushed or merged yet. The branch is now deleted locally.
The command to delete a remote branch is: Instead of using the git branch command that you use for local branches, you can delete a remote branche with the git push command. Then you specify the name of the remote, which in most cases is origin.
Use it only when you are absolutely sure you want to delete a local branch. If you didn't merge it into another local branch or push it to a remote branch in the codebase, you will risk losing any changes you've made. Remote branches are separate from local branches. They are repositories hosted on a remote server that can be accessed there.
type git branch to get the list of all branches. if the renamed branch is not pushed to the remote then you can push it normally by if the renamed branch is already there on the remote ( if you push it using the above method, it will create a new branch instead of replacing it) use
Back to the previous example, if you want to delete the remote Git tag named “v1.0”, you would run To delete a remote Git tag, you can also use the “git push” command and specify the tag name using the refs syntax.
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 take care of the scenario in the question:
$ git push origin :refs/heads/0.2.0.0
And for completeness, if it was the tag that was unwanted:
$ git push origin :refs/tags/0.2.0.0
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With