How can I delete all Git branches which have been merged?

后端 未结 30 1094
离开以前
离开以前 2020-11-22 14:22

I have many Git branches. How do I delete branches which have already been merged? Is there an easy way to delete them all instead of deleting them one by one?

30条回答
  •  遇见更好的自我
    2020-11-22 15:20

    You'll want to exclude the master & develop branches from those commands.

    Local git clear:

    git branch --merged | grep -v '\*\|master\|develop' | xargs -n 1 git branch -d
    

    Remote git clear:

    git branch -r --merged | grep -v '\*\|master\|develop' | sed 's/origin\///' | xargs -n 1 git push --delete origin
    

    Sync local registry of remote branches:

    git fetch -p
    

提交回复
热议问题