How to delete all remote git branches which have already been integrated?

后端 未结 6 1959
暖寄归人
暖寄归人 2021-01-30 09:21

At work we are using topic branches which are integrated into a few (3) master branches at some point. Now I\'d like to delete all topic branches from my remote reposit

6条回答
  •  [愿得一人]
    2021-01-30 09:33

    For a Windows box I use this PowerShell oneliner to clean all merged remote git branches on a weekly basis using Windows Scheduled Tasks on our build system:

    git branch --all --merged remotes/origin/master | Select-String -NotMatch "master" | Select-String -NotMatch "HEAD" | Select-String "remotes/origin/" | Foreach-Object { $_.ToString().Replace("remotes/origin/", "").Trim() } | Foreach-Object { git.exe push origin --delete $_ }
    

    Remark: it combines most of the answers already given but without capping the number of branch cleans.

提交回复
热议问题