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

$ 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 branch -d <branch_name>

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

git branch -D <branch_name>

远程删除 :

有两个选项:

git push origin :branchname

git push origin --delete branchname

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

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

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

然后您可以拨打:

git-shoot branchname

删除分行

我们假设我们的分支“联系形式”的工作已经完成, 我们已经把它融入了“ 主管” 。 既然我们不再需要它, 我们可以删除它( 本地) : git 分支 $ git - d 联系形式 。

要删除远程分支 :

git push origin --delete contact-form

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

$ 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 push --prune origin

警告: 这将删除所有本地不存在的远程分支。 或者更全面地说,

git push --mirror

将有效地使远程存储库看起来像本地版本的存储库(本地负责人、远程和标签在远程镜像) 。