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

后端 未结 30 1056
离开以前
离开以前 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:24

    For those of you that are on Windows and prefer PowerShell scripts, here is one that deletes local merged branches:

    function Remove-MergedBranches
    {
      git branch --merged |
        ForEach-Object { $_.Trim() } |
        Where-Object {$_ -NotMatch "^\*"} |
        Where-Object {-not ( $_ -Like "*master" )} |
        ForEach-Object { git branch -d $_ }
    }
    

提交回复
热议问题