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

$ 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本地和远程分支?


当前回答

自2013年1月以来,GitHub包括删除分支按钮旁边的“Branches”页面中的每个分支。

相关博客文章:创建和删除分支

其他回答

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

删除远程分支

git push origin :<branchname>

删除本地分支

git branch -D <branchname>

删除本地分支步骤 :

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

使用 :

git push origin :bugfix  # Deletes remote branch
git branch -d bugfix     # Must delete local branch manually

如果您确定要删除,请运行

git branch -D bugfix

现在清理已删除的远程分支, 运行

git remote prune origin

A A A一班班要删除的命令本地和偏远地区:

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

或者将下面的别名添加到您的~ /. git config ~ /. git config用法:git kill branch-name

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

答案是好的, 但是, 如果您有一大堆分支, 逐个删除本地和远程的分支, 将会是一个无聊的任务 。 您可以使用此脚本将这些任务自动化 。

branch_not_delete=( "master" "develop" "our-branch-1" "our-branch-2")

for branch in `git branch -a | grep remotes | grep -v HEAD | grep -v master`; do

    # Delete prefix remotes/origin/ from branch name
    branch_name="$(awk '{gsub("remotes/origin/", "");print}' <<< $branch)"

    if ! [[ " ${branch_not_delete[*]} " == *" $branch_name "* ]]; then
        # Delete branch remotly and locally
        git push origin :$branch_name
    fi
done
  • 列出您不想删除的分支
  • 绕过遥控器的分支 如果它们不在我们的“保护名单”里 就会删除它们

资料来源:立即删除 Git 分支