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

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


当前回答

如果您想要用一个命令来完成这两个步骤, 您可以在 ~ /. 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(小写d),该分支只有在合并时才被删除。要强制删除,您需要使用 -D(大写D)。

其他回答

删除远程分支

git 推推源 : <branchname>

删除本地分支

git 分支 -D <branchname>

删除本地分支步骤 :

退出退出到另一个分支删除本地分支

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

一班级命令,删除本地和远程两个部分:

D=branch-name; git branch -D $D; git push origin :$D

或添加以下别名到 ~/. gitconfig 的 ~ /. gitconfig 。 用法: git 杀死分支名称

[alias]
    kill = "!f(){ git branch -D \"$1\";  git push origin --delete \"$1\"; };f"

我在我的. gitconfig 文件中添加了以下别名。 这样可以删除分支, 不论是否指定分支名称 。 如果没有通过参数, 分支名称默认为当前分支 。

[alias]
    branch-name = rev-parse --abbrev-ref HEAD     

    rm-remote-branch = !"f() { branch=${1-$(git branch-name)}; git push origin :$branch; }; f"
    rm-local-branch = !"f() { branch=${1-$(git branch-name)}; git checkout master; git branch -d $branch; }; f"
    rm-branch-fully = !"f() { branch=${1-$(git branch-name)}; git rm-local-branch $branch; git rm-remote-branch $branch; }; f"

很简单: 只要运行以下命令 :

要删除本地和远程的 Git 分支, 请使用此命令先删除本地分支 :

git branch -d example

(此处为分支名称 。)

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

git push origin :example