Skip to content

Instantly share code, notes, and snippets.

@jseed
Last active February 7, 2024 10:01
Show Gist options
  • Star 28 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save jseed/5d022570ea52ee09a8f43913214496f1 to your computer and use it in GitHub Desktop.
Save jseed/5d022570ea52ee09a8f43913214496f1 to your computer and use it in GitHub Desktop.
PowerShell command to delete all branches except master
git checkout master; git branch -D @(git branch | select-string -NotMatch "master" | Foreach {$_.Line.Trim()})
@RageCage64
Copy link

Thanks for this! I'm a Linux guy stuck on Windows and had no idea how to do this without grep. 😄

@Xceldeveloper
Copy link

This also works on PowerShell
git branch | Select-String -NotMatch -Pattern "master" | %{ git branch -D $_.ToString().Trim() }

@nickgayo12
Copy link

Big help, Thanks!

@kiview
Copy link

kiview commented Jan 5, 2022

I knew this had to be out there somewhere, thanks!

@icodeintx
Copy link

Thank You!

@andrewchaa
Copy link

Thanks!

@anujpradhaan
Copy link

You are a savior!

@data-miner00
Copy link

Thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment