aWebDeveloper
aWebDeveloper

Reputation: 38352

Delete a remote branch with the same name as tag

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.

Upvotes: 58

Views: 9076

Answers (3)

VonC
VonC

Reputation: 1323973

You can push the full branch refspec:

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

git push --delete refs/heads/3.0.0
# shorter
git push -d refs/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 deletion.

Because the refspec is <src>:<dst>, by leaving off the <src> part, this basically says to make the topic branch on the remote "nothing", which deletes it.

I mentioned the alternative --delete syntax here: git push -d.

Upvotes: 67

Tydaeus
Tydaeus

Reputation: 1605

The --delete option works for this purpose as long as you specify the ref you're deleting unambiguously:

git push origin --delete refs/tags/<tagname>

Or for a branch:

git push origin --delete refs/heads/<branchname>

Upvotes: 1

Felipe Alvarez
Felipe Alvarez

Reputation: 3898

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>

The empty string to the left of the colon causes the remote reference to be deleted.

Upvotes: 8

Related Questions