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

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

较容易记住

git push origin :branchName

其他回答

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

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

我在我的. 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 推进源 - delette <branch- name > 删除您的本地分支 - git 分支 - delette < branch- name >

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

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