How do I delete a remote branch in Git?

Git

Git Problem Overview


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

Git Solutions


Solution 1 - Git

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

Solution 2 - Git

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 

Solution 3 - Git

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".

Solution 4 - Git

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

Solution 5 - Git

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}

Solution 6 - Git

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionchrisaycockView Question on Stackoverflow
Solution 1 - GitIonuČ› G. StanView Answer on Stackoverflow
Solution 2 - GitOleg AbrazhaevView Answer on Stackoverflow
Solution 3 - GitjasonrudolphView Answer on Stackoverflow
Solution 4 - GitaashaView Answer on Stackoverflow
Solution 5 - GitTomView Answer on Stackoverflow
Solution 6 - GitLuca BorrioneView Answer on Stackoverflow