如何删除仍在本地显示的"远程"分支?

koj*_*iro 12 git git-branch

无意中创建了一个分支.我想删除它.事实上,我认为我上周删除了它,并且它没有出现在bitbucket的搜索中,所以我倾向于认为问题只在我的本地回购中.为什么分支仍然出现在我的本地仓库中?

$ git branch -d ebc_193_157_154_order_creation_xsd_validation_and_refactored_code
error: branch 'ebc_193_157_154_order_creation_xsd_validation_and_refactored_code' not found.
$ git push bitbucket :ebc_193_157_154_order_creation_xsd_validation_and_refactored_code
error: unable to delete 'ebc_193_157_154_order_creation_xsd_validation_and_refactored_code': remote ref does not exist
error: failed to push some refs to 'bitbucket.org:trueaction/eb2c'
Run Code Online (Sandbox Code Playgroud)

它仍然是:

$ git branch -r | grep ebc_193
  bitbucket/ebc_193_157_154_order_creation_xsd_validation_and_refactored_code
$ git branch -a | grep ebc_193
  remotes/bitbucket/ebc_193_157_154_order_creation_xsd_validation_and_refactored_code
Run Code Online (Sandbox Code Playgroud)

我该怎么做才能摆脱它?

Ben*_*ier 22

您正在寻找git remote prune哪些删除陈旧的远程分支.

删除所有过时的远程跟踪分支.这些陈旧的分支已经从引用的远程存储库中删除,但仍然在"远程/"中本地可用.

使用--dry-run选项,报告将修剪哪些分支,但实际上不要修剪它们.

在你的情况下,你会想要使用git remote prune origin.

  • 例如,`git remote prune -n​​ origin`报告将在原点上修剪的内容,并且`git remote prune origin`实际上进行修剪. (5认同)