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

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


当前回答

git branch -D <name-of-branch>
git branch -D -r origin/<name-of-branch>
git push origin :<name-of-branch>

其他回答

如果您想要删除分支, 请先向要删除的分支以外的分支首选 。

git checkout other_than_branch_to_be_deleted

删除本地分支 :

git branch -D branch_to_be_deleted

删除远程分支 :

git push origin --delete branch_to_be_deleted

删除远程分支

git push origin :<branchname>

删除本地分支

git branch -D <branchname>

删除本地分支步骤 :

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

您也可以使用git remote prune origin

$ git remote prune origin
Pruning origin
URL: git@example.com/yourrepo.git
 * [pruned] origin/some-branchs

它利用和删除了远程跟踪分支和远程跟踪分支。git branch -r列表。

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

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

现在,你可以做它与GitHub 桌面桌面应用程序。

启动申请程序后

  1. 点击含有分支的工程
  2. 切换到您想要删除的分支

    Switching branch

  3. 从“ Branch” 菜单中选择“ 不出版... ” , 将分支从 GitHub 服务器中删除 。

    Unpublish branch

  4. 从“ 空白” 菜单中选择“ 删除”分支组名称"""",""",""",""","""","""",""""","""","""""","""""","""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

    Delete local branch