How do I delete a Git branch locally and remotely?

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

    If you want to complete both these steps with a single command, you can make an alias for it by adding the below to your ~/.gitconfig:

    [alias]
        rmbranch = "!f(){ git branch -d ${1} && git push origin --delete ${1}; };f"
    

    Alternatively, you can add this to your global configuration from the command line using

    git config --global alias.rmbranch \
    '!f(){ git branch -d ${1} && git push origin --delete ${1}; };f'
    

    NOTE: If using -d (lowercase d), the branch will only be deleted if it has been merged. To force the delete to happen, you will need to use -D (uppercase D).

提交回复
热议问题