94

I created a branch notmaster to commit as well as push some changes. When I was finished with that branch, I merged the changes back into master, pushed them out, and then deleted the local notmaster.

$ git branch -a
* master
  remotes/origin/master
  remotes/origin/notmaster

Is there anyway to delete the remote notmaster?


A little more clarity, with the solution from Ionut:

The usual method failed for me:

$ git push origin :notmaster
error: dst refspec notmaster matches more than one.

That's because I had a tag with the same name as the branch. This was a poor choice on my behalf and caused the ambiguity. So in that case:

$ git push origin :refs/heads/notmaster
Community
  • 1
  • 1
chrisaycock
  • 36,470
  • 14
  • 88
  • 125
  • 2
    I Love you! I have been trying to get over the same problem for hours now! This is why I love StackOverflow +1!!! – Logan Dec 18 '12 at 13:05

6 Answers6

61

I had the same issue. I had both a branch and a tag named 3.2. That's why it says there's more than one match:

git error: dst refspec 3.2 matches more than one.

Here's how to delete the branch:

git push origin :heads/3.2

And here's how to delete the tag:

git push origin :tags/3.2 
wolverdude
  • 1,583
  • 1
  • 13
  • 20
Oleg Abrazhaev
  • 2,751
  • 2
  • 28
  • 41
60

git push origin :notmaster, which basically means "push nothing to the notmaster remote".

Ionuț G. Stan
  • 176,118
  • 18
  • 189
  • 202
  • 4
    error: dst refspec notmaster matches more than one. – chrisaycock Nov 11 '10 at 22:39
  • That's a first. I haven't seen that error before. – Ionuț G. Stan Nov 11 '10 at 22:40
  • 3
    Ah, your second suggestion worked! I have a tag with the same label as that branch (notmaster). Could that cause the error? – chrisaycock Nov 11 '10 at 22:41
  • 23
    Oh, yes, that's the cause. I believe you could have deleted it using `git push origin :refs/heads/notmaster`. Not sure though. – Ionuț G. Stan Nov 11 '10 at 22:45
  • @chrisaycock: That's exactly what caused it. Generally you should avoid duplicating names like that, since some commands work with both tags and branches and become ambiguous. – Cascabel Nov 11 '10 at 22:47
  • 11
    @chrisaycock: And in fact, you *need* to do what Ionut suggests (disambiguate to refs/heads/notmaster) because with the `git branch -d -r` command, you've only deleted the local remote tracking branch, not the actual branch on the remote. If you don't delete it on the remote, it'll just show up the next time you fetch. – Cascabel Nov 11 '10 at 22:48
  • @Jefromi is right, I've just re-read what the manual says. – Ionuț G. Stan Nov 11 '10 at 22:49
  • Yup 6h6is yawn at 8l999 – Benny Skogberg Jul 23 '18 at 18:27
16
git push origin --delete notmaster

If you're using Git 1.7.0 or later, this will do the trick. Prior to Git 1.7.0, you needed to use the less intuitive (but equally effective) syntax:

git push origin :notmaster

The older syntax still works in newer versions of Git, but the newer syntax seems more humane and easier to remember. If I want to delete a branch, typing --delete seems like the natural thing to do.

From the 1.7.0 release notes:

"git push" learned "git push origin --delete branch", a syntactic sugar for "git push origin :branch".

jasonrudolph
  • 573
  • 3
  • 8
7

This happened because the name of the branch and tag is same.

To delete the branch from remote use

git push origin :refs/heads/branchname

To delete the tag from remote use

git push origin :refs/tags/tagname

To delete from local you can use the following.

git branch -d branchname

git tag -d tagname

aasha
  • 446
  • 4
  • 11
1

Delete local branch:

git branch -d {branch name} //All changes must be committed first.
git branch -D {branch name} //Does not require commit.

Delete Gitorious Branch:

Delete the local branch first.
git push {gitorious push url} :{branch name}
Tom
  • 1,971
  • 3
  • 22
  • 32
  • 3
    The second of your two answers is what the OP was looking for, though it's by no means specific to gitorious, and you don't need a URL - just a remote name, which the OP gave. `git push origin :notmaster`, or in this case, `git push origin :refs/heads/notmaster` would be a clearer answer. – Cascabel Nov 11 '10 at 22:59
0

The following steps can do the trick as well:

$ git fetch --prune --tags
$ git push origin :refs/tags/{same-branch-tag-name}
$ git push origin :{same-branch-tag-name}
$ git push --tags
Luca Borrione
  • 16,324
  • 8
  • 52
  • 66