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

$ 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 remote prune origin

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

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

其他回答

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

git checkout other_than_branch_to_be_deleted

删除本地分支 :

git branch -D branch_to_be_deleted

删除远程分支 :

git push origin --delete branch_to_be_deleted

我用下面的 在我的巴什设置 :

alias git-shoot="git push origin --delete"

然后您可以拨打:

git-shoot branchname

执行前执行前

git branch --delete <branch>

确保您首先确定精确远程分支的名称是执行 :

git ls-remote

这将告诉您要进入什么精确用于<branch>值 。 () (branch案件敏感! )

本地和远程删除您的分支

  • 取出至母版分支 -git checkout master

  • 删除您的远程分支 -git push origin --delete <branch-name>

  • 删除您的本地分支 -git branch --delete <branch-name>

我厌倦了勾勾勾勾勾勾勾勾勾勾勾的答案, 所以我采取了类似的办法,克雷格所发回的答案早些时候。

我在我的巴什档案中增加了以下内容:

function gitdelete(){
    git push origin --delete $1
    git branch -D $1
}

每当我完成一个分支(合并成master例如)我在我的终端运行以下功能:

gitdelete my-branch-name

...然后删除my-branch-name调自origin以及当地。