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

$ 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 branch --delete <branch>

确保您首先通过执行确定远程分支的确切名称 :

git ls-remote

这将指示您为 < branch> 值输入什么 。 ( branch 是区分大小写 ! )

其他回答

这是所有其他答案的拼图。 它需要 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

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

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

$ 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.

图形代表:

Matthew的回答对移除远程树枝很有帮助, 我也欣赏这一解释,

要从您的机器中删除本地分支 : git 分支 - d { local_ branch} (使用 - D 代替强制删除分支而不检查合并状态); 从服务器中删除远程分支 : git 推源 - d {remote_ branch} 。

参考: Git: 删除分支( 本地或远程) 。