删除远程分支的尝试失败 :

$ git branch -d remotes/origin/bugfix
error: branch 'remotes/origin/bugfix' not found.

$ git branch -d origin/bugfix
error: branch 'origin/bugfix' not found.

$ git branch -rd origin/bugfix
Deleted remote branch origin/bugfix (was 2a14ef7).

$ git push
Everything up-to-date

$ git pull
From github.com:gituser/gitproject

* [new branch] bugfix -> origin/bugfix
Already up-to-date.

我如何正确删除本地和远程的远程/原产/bugfix分支?


当前回答

如果您有一个标签, 标签名称与遥控器上的分支相同, 这行不通 :

$ git push origin :branch-or-tag-name
error: dst refspec branch-or-tag-name matches more than one.
error: failed to push some refs to 'git@github.com:SomeName/some-repo.git'

在此情况下, 您需要指定要删除分支, 而不是标记 :

git push origin :refs/heads/branch-or-tag-name

类似地, 要删除标签, 而不是您要使用的分支 :

git push origin :refs/tags/branch-or-tag-name

其他回答

删除本地端 - (正常)

git branch -d my_branch

如果分行处于调整/合并的进度中,且未正确完成,这意味着您将会出错, 重设/ 计量在进行中, 因此在这种情况下, 您将无法删除分行 。

所以要么你需要解决重置/合并问题。 否则,你可以通过使用, 强制删除,

git branch -D my_branch

要删除远程 :

git push --delete origin my_branch

您可以使用 :

git push origin :my_branch   # Easy to remember both will do the same.

图形代表:

您也可以使用以下内容删除远程分支

git push --delete origin serverfix

git push origin :serverfix

但它可能更容易记住。

最初的几种方法对我行不通。

假设你有以下分支和远程分支,

Local : Test_Branch
Remote: remotes/origin/feature/Test_FE

正确设置上方为您本地分支以跟踪您想要删除的远程分支 。

git branch --set-upstream-to=remotes/origin/feature/Test_FE Test_Branch

然后删除远程分支执行此任务

git push origin --delete Test_Branch

然后删除本地分支,按照命令执行

git branch -D Test_Branch

就是这样。

一班级命令,删除本地和远程两个部分:

D=branch-name; git branch -D $D; git push origin :$D

或添加以下别名到 ~/. gitconfig 的 ~ /. gitconfig 。 用法: git 杀死分支名称

[alias]
    kill = "!f(){ git branch -D \"$1\";  git push origin --delete \"$1\"; };f"

我在我的巴什设置中使用了以下内容:

alias git-shoot="git push origin --delete"

然后您可以拨打:

git-shoot branchname