Last active
March 12, 2025 08:52
-
-
Save jseed/5d022570ea52ee09a8f43913214496f1 to your computer and use it in GitHub Desktop.
PowerShell command to delete all branches except master
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git checkout master; git branch -D @(git branch | select-string -NotMatch "master" | Foreach {$_.Line.Trim()}) |
This also works on PowerShell
git branch | Select-String -NotMatch -Pattern "master" | %{ git branch -D $_.ToString().Trim() }
Big help, Thanks!
I knew this had to be out there somewhere, thanks!
Thank You!
Thanks!
You are a savior!
Thank you very much!
Thanks!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this! I'm a Linux guy stuck on Windows and had no idea how to do this without grep. 😄