如何仅从本地git删除远程分支?

问题描述:

我知道命令 git push -d< remote>< branch_name>

我只想从我的本地git env 中删除远程分支.上面的命令也会从我的本地和远程github上删除远程分支.

I want to delete remote branch only from my local git env. The command above removes remote branch from my local and remote github also.

但是,如果我像这样直接在github 中删除了远程分支

However, if I had removed remote branch in github directly like this,

远程中不再有名为 feature/search 的分支,该命令将失败.

there is no branch named feature/search in remote anymore, the command fails.

那么,如何在不与远程github交互的情况下删除本地的远程分支?

So, how can I remove remote branch in my local without interacting remote github?

以前在此处回答..strong>

Previously answered here.

您可以使用 git branch -D git branch -d 在本地删除分支.

You can use git branch -D or git branch -d for deleting a branch locally.

来自官方文档

  -d
  --delete
  Delete a branch. The branch must be fully merged in its upstream branch, or in HEAD if 
  no upstream was set with --track or --set-upstream-to.

  -D
  Shortcut for --delete --force.


您的情况应该是


In your case, it should be,

  git branch -d feature/search