How to remove all merged Git Branches on Windows

Here’s a quick tip on howto remove Git Branches that were already merged (thus not necessary to keep around anymore) locally on Windows, using PowerShell. Assuming that you do have Git for Windows installed. Execute these commands on your own risk. List all merged branches You can list all merged Git Branches by running: 1 git branch --merged Exclude current branch and “main” branch Then we |-pipe it into the following, to exclude the currently selected branch (marked with an asterisk *) and the main branch. This regex filter query does not aim to be universally good. So if you have branches that include the term main in their name, those will be excluded aswell. I didn’t care to optimize, because I don’t name my branches in such a weird way. ...

2022-06-21 · 2 min · Andreas Dieckmann