How do I delete a Git branch locally and remotely?

后端 未结 30 3576
被撕碎了的回忆
被撕碎了的回忆 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条回答
  •  梦毁少年i
    2020-11-21 05:03

    Many of the other answers will lead to errors/warnings. This approach is relatively fool proof although you may still need git branch -D branch_to_delete if it's not fully merged into some_other_branch, for example.

    git checkout some_other_branch
    git push origin :branch_to_delete
    git branch -d branch_to_delete
    

    Remote pruning isn't needed if you deleted the remote branch. It's only used to get the most up-to-date remotes available on a repository you're tracking. I've observed git fetch will add remotes, not remove them. Here's an example of when git remote prune origin will actually do something:

    User A does the steps above. User B would run the following commands to see the most up-to-date remote branches:

    git fetch
    git remote prune origin
    git branch -r
    

提交回复
热议问题