Cleaning up all git merged local branches

Posted by

I came across a useful script I wanted to share today. This deletes all local git branches that have been merged, and are not “main” or “master”. This is challenging in Visual Studio today, deleting the branches one by one is slow and manual.

In PowerShell:

git branch --merged | %{$_.trim()}  | ?{$_ -notmatch 'master' -and $_ -notmatch 'main'} | %{git branch -d $_.trim()}

References

One comment

Leave a Reply to adamrushuk Cancel reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s