How do I delete a Git branch locally and remotely?

后端 未结 30 3581
被撕碎了的回忆
被撕碎了的回忆 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 05:04

    To delete locally - (normal)

    git branch -d my_branch
    

    If your branch is in a rebasing/merging progress and that was not done properly, it means you will get an error, Rebase/Merge in progress, so in that case, you won't be able to delete your branch.

    So either you need to solve the rebasing/merging. Otherwise, you can do force delete by using,

    git branch -D my_branch
    

    To delete in remote:

    git push --delete origin my_branch
    

    You can do the same using:

    git push origin :my_branch   # Easy to remember both will do the same.
    

    Graphical representation:

提交回复
热议问题