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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4159950/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 04:44:19  来源:igfitidea点击:

How do I delete a remote branch in Git?

git

提问by chrisaycock

I created a branch notmasterto 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.

我创建了一个分支notmaster来提交并推送一些更改。当我与该分支完成后,我合并将更改回复到master,推他们出来,然后被删除本地notmaster

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

Is there anyway to delete the remote notmaster?

有没有办法删除遥控器notmaster



A little more clarity, with the solution from Ionut:

更清晰一点,来自 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

采纳答案by Ionu? G. Stan

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

git push origin :notmaster,这基本上意味着“不向 notmaster 遥控器推送任何内容”。

回答by Oleg Abrazhaev

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:

我遇到过同样的问题。我有一个分支和一个名为 3.2 的标签。这就是为什么它说有不止一场比赛:

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 

回答by jasonrudolph

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 1.7.0 或更高版本,这可以解决问题。在 Git 1.7.0 之前,您需要使用不太直观(但同样有效)的语法:

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 deletea branch, typing --deleteseems like the natural thing to do.

较旧的语法在较新版本的 Git 中仍然有效,但较新的语法似乎更人性化,更容易记住。如果我想删除一个分支,打字--delete似乎是很自然的事情。

From the 1.7.0 release notes:

1.7.0 发行说明

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

“git push”学习了“git push origin --delete branch”,这是“git push origin :branch”的语法糖。

回答by aasha

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

git push origin :refs/heads/branchname

To delete the tag from remote use

从远程使用中删除标签

git push origin :refs/tags/tagname

git push origin :refs/tags/tagname

To delete from local you can use the following.

要从本地删除,您可以使用以下命令。

git branch -d branchname

git branch -d branchname

git tag -d tagname

git tag -d tagname

回答by Tom

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:

删除 Gitorious 分支:

Delete the local branch first.
git push {gitorious push url} :{branch name}

回答by Luca Borrione

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