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

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

我如何正确删除remotes/origin/bugfix本地和远程分支?


当前回答

这是所有其它答案的混结。 它需要Ruby 1.9. 3+, 并经过测试仅仅OS X上写着

调用此文件git-remove,然后使用,例如,git remove temp.

#!/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

其他回答

如果您想要用一个单命令来完成这两个步骤, 您可以在您的~/.gitconfig:

[alias]
    rmbranch = "!f(){ git branch -d ${1} && git push origin --delete ${1}; };f"

或者,您可以从命令行使用

git config --global alias.rmbranch \
'!f(){ git branch -d ${1} && git push origin --delete ${1}; };f'

注 注 注 注 注注:如果使用-d(lowercase d) , 分支分支只有在合并时才被删除 。 要强制删除, 您需要使用-D(多例D)。

使用吉特巴什您可以执行以下操作:

git branch --delete <branch>

-

从 GitHub 桌面应用程序中删除当地当地通过分支通过分处菜单条 :

Enter image description here

如果你(如果)不属于使用 GitHub 桌面应用程序, 并正在使用像视觉工作室那样的 IDE 来控制本地源码, 您只需要快速的一步 :

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

然后,一旦登录到您的 GitHub 账户, 一旦登录到您的 GitHub 在线账户, 转到存储库并单击所有各处选项卡。从此选项卡中,单击您想要删除的分支名称右侧的小垃圾桶图标。

Enter image description here

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

马修的回答可用于删除偏远我也感谢这一解释,但要简单区分两个命令:

  • 要删除地方分支来自您的机器 :git branch -d {local_branch}(使用-D而不是强制删除分支,而不检查合并状态);

  • 要删除远程分支来自服务器的 :git push origin -d {remote_branch}.

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

git push origin --delete <branch Name>

较容易记住

git push origin :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