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

$ 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 checkout other_than_branch_to_be_deleted

删除本地分支 :

git branch -D branch_to_be_deleted

删除远程分支 :

git push origin --delete branch_to_be_deleted

其他回答

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

最初的几种方法对我行不通。

假设你有以下分支和远程分支,

Local : Test_Branch
Remote: remotes/origin/feature/Test_FE

正确设置上方为您本地分支以跟踪您想要删除的远程分支 。

git branch --set-upstream-to=remotes/origin/feature/Test_FE Test_Branch

然后删除远程分支执行此任务

git push origin --delete Test_Branch

然后删除本地分支,按照命令执行

git branch -D Test_Branch

就是这样。

本地和远程删除您的分支

退出到母版分支 - git 检查退出母版母版 删除您的远程分支 - git 推进源 - delette <branch- name > 删除您的本地分支 - git 分支 - delette < branch- name >

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

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