Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete a remote branch with the same name as tag

Tags:

git

I have a branch and a tag by the name 3.0.0. Now how do i only delete the branch not the tag.

I tried

git push origin --delete 3.0.0 error: dst refspec 3.0.0 matches more than one. 
like image 444
aWebDeveloper Avatar asked Oct 03 '15 20:10

aWebDeveloper


People also ask

How do I delete a remote branch?

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 .

Can you have a branch and a tag with the same name?

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.

What happens to tag when branch is deleted?

The tag and commit would still exist if the branch is deleted. A branch is simply a way to track a collection of commits.

Is it okay to delete a branch in your remote repository?

It is safe to delete your local branch after you pushed your changes to your own remote repository. The pull request is unrelated to this, because it is simply a request to the maintainers of the original repository to merge your changes back into their code base.


2 Answers

You can push the full branch refspec:

git push origin :refs/heads/3.0.0 # shorter: git push origin :heads/3.0.0 

That would reference only a branch, not a tag (refs/tags/3.0.0).

Here the refspec has no source in front of the ':': that means HEAD.
:refs/heads/3.0.0 is HEAD:refs/heads/3.0.0.
That means you need to checkout the correct branch before pushing.

like image 68
VonC Avatar answered Sep 26 '22 02:09

VonC


I came here looking for a way to delete remote tag with same name as branch. Following from the Giants comments above, I found this worked:

git push <remote> :refs/tags/<mytag> # or git push origin :tags/<mytag> 
like image 35
Felipe Alvarez Avatar answered Sep 26 '22 02:09

Felipe Alvarez