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

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

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

git ls-remote

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

提示:当您使用删除分支时

git branch -d <branchname> # Deletes local branch

git push origin :<branchname> # Deletes remote branch

仅删除引用 。 即使该分支实际上被远程删除, 但它的引用仍然存在于您的团队成员所在的本地存储库中 。 这意味着对于其他团队成员来说, 被删除的分支在做 Git 分支 - a 时仍然可见 。

为了解决这个问题,你的团队成员可以使用

git remote prune <repository>

这是典型的 Git 远程纯素来源 。

这是所有其他答案的拼图。 它需要 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 分支, 请使用此命令先删除本地分支 :

git branch -d example

(此处为分支名称 。)

在此之后, 使用此命令删除远程分支 :

git push origin :example