How do I delete a Git branch locally and remotely?

后端 未结 30 3611
被撕碎了的回忆
被撕碎了的回忆 2020-11-21 04:11

I want to delete a branch both locally and remotely.

Failed Attempts to Delete a Remote Branch

$ git branch -d         


        
30条回答
  •  一向
    一向 (楼主)
    2020-11-21 04:50

    This won't work if you have a tag with the same name as the branch on the remote:

    $ git push origin :branch-or-tag-name
    error: dst refspec branch-or-tag-name matches more than one.
    error: failed to push some refs to 'git@github.com:SomeName/some-repo.git'
    

    In that case you need to specify that you want to delete the branch, not the tag:

    git push origin :refs/heads/branch-or-tag-name
    

    Similarly, to delete the tag instead of the branch you would use:

    git push origin :refs/tags/branch-or-tag-name
    

提交回复
热议问题