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

$ 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分支?


当前回答

这是所有其他答案的拼图。 它需要 Ruby 1.9. 3 +, 并且只在 OS X 上测试 。

调用此文件 git- remove, 让它可执行, 并把它放在您的路径中。 然后使用, 例如, git 删除临时 。

#!/usr/bin/env ruby
require 'io/console'

if __FILE__ == $0
      branch_name = ARGV[0] if (ARGV[0])
      print "Press Y to force delete local and remote branch #{branch_name}..."
    response = STDIN.getch
    if ['Y', 'y', 'yes'].include?(response)
      puts "\nContinuing."
      `git branch -D #{branch_name}`
      `git branch -D -r origin/#{branch_name}`
      `git push origin --delete #{branch_name}`
    else
      puts "\nQuitting."
    end
end

其他回答

使用 Git Bash 您可以执行以下操作 :

git branch --delete <branch>

- 带

从 GitHub 桌面应用程序中, 当您检查了分支时, 您可以通过分支菜单条删除本地分支 :

如果您没有使用 GitHub 桌面应用程序, 并且正在使用像视觉工作室那样的 IDE 来控制本地源码, 您只需要采取几个快速步骤 :

检查您要删除的分支以外的分支。右键单击您想要删除的分支。从上下文菜单中选择删除选项。

然后,一旦在网上登录到您的 GitHub 账户, 转到仓库, 并单击所有分支的标签。 从那里, 单击小垃圾桶就可以在右侧您想要删除的分支的名称上图标 。

无需试图从你的网上存储库删除。

自2013年1月以来, GitHub 在您的“ Branches” 页中, 在每个分支旁边有一个删除分支按钮 。

相关博客文章: 创建和删除分支

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

git push --delete origin serverfix

git push origin :serverfix

但它可能更容易记住。

如果您想要删除分支, 请先向要删除的分支以外的分支首选 。

git checkout other_than_branch_to_be_deleted

删除本地分支 :

git branch -D branch_to_be_deleted

删除远程分支 :

git push origin --delete branch_to_be_deleted

本地删除 :

要删除本地分支,请使用:

git branch -d <branch_name>

强行删除分支,使用 -D 而不是 -d 。

git branch -D <branch_name>

远程删除 :

有两个选项:

git push origin :branchname

git push origin --delete branchname

我建议你用第二种方式,因为它更直观。