如何删除 Git 中的远程分支?

我创建了一个分支 notmaster来提交以及推送一些更改。当我完成这个分支时,我将更改合并回 master,将它们推出,然后删除本地 notmaster

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

有办法删除远程 notmaster吗?


对于 来自 Ionut 的解决方案,再清晰一点:

通常的方法对我来说失败了:

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

那是因为我有一个标签和分行的名字一样。这对我来说是个糟糕的选择,导致了这种模棱两可。所以在这种情况下:

$ git push origin :refs/heads/notmaster
22425 次浏览

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

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

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

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

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