Skip to content

Instantly share code, notes, and snippets.

@peteraritchie
Last active December 28, 2025 18:47
Show Gist options
  • Select an option

  • Save peteraritchie/c131d25e65f79be9e2e4a3bfe2fc3020 to your computer and use it in GitHub Desktop.

Select an option

Save peteraritchie/c131d25e65f79be9e2e4a3bfe2fc3020 to your computer and use it in GitHub Desktop.
Delete git branches merged to main

Delete git branches merged to main

A simple powershell script to clean up local branches that have been merged to main:

git branch --merged main | Foreach-object { if($_.SubString(0,1) -ne '*'){ git branch -d $_.SubString(2);} }

Delete branches that have been removed in origin

git remote prune origin

Delete branches other than current

git branch | Foreach-object { if($_.SubString(0,1) -ne '*'){ git branch -d $_.SubString(2);} }

Force delete branches other than current

git branch | Foreach-object { if($_.SubString(0,1) -ne '*'){ git branch -D $_.SubString(2);} }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment