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

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


当前回答

删除远程分支的命令行的替代选项是GitHub 分支页面.

例如,见:https://github.com/angular/angular.js/branches

发现于Code -> BranchesGitHub 库页面。

我一般都更喜欢指挥线 但这个GitHub 页面显示更多信息,树的枝枝的枝枝,例如最新更新日期和用户, 和未来和后承诺数在与大量分支机构打交道时非常有用。

其他回答

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

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

本地删除 :

要删除本地分支,请使用:

git branch -d <branch_name>

强行删除分支,使用-D代替-d.

git branch -D <branch_name>

远程删除 :

有两个选项:

git push origin :branchname

git push origin --delete branchname

我建议你用第二种方式,因为它更直观。

之后我加了以下别名.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 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列表。