How do I delete a Git branch locally and remotely?

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

    Steps for deleting a branch:

    For deleting the remote branch:

    git push origin --delete 
    

    For deleting the local branch, you have three ways:

    1: git branch -D 
    
    2: git branch --delete --force   # Same as -D
    
    3: git branch --delete           # Error on unmerge
    

    Explain: OK, just explain what's going on here!

    Simply do git push origin --delete to delete your remote branch only, add the name of the branch at the end and this will delete and push it to remote at the same time...

    Also, git branch -D, which simply delete the local branch only!...

    -D stands for --delete --force which will delete the branch even it's not merged (force delete), but you can also use -d which stands for --delete which throw an error respective of the branch merge status...

    I also create the image below to show the steps:

提交回复
热议问题