Skip to content

Instantly share code, notes, and snippets.

@jseed
Last active March 12, 2025 08:52
Show Gist options
  • Select an option

  • Save jseed/5d022570ea52ee09a8f43913214496f1 to your computer and use it in GitHub Desktop.

Select an option

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
Copy Markdown

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

@Xceldeveloper

Copy link
Copy Markdown

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

@nickgayo12

Copy link
Copy Markdown

Big help, Thanks!

@kiview

kiview commented Jan 5, 2022

Copy link
Copy Markdown

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

@icodeintx

Copy link
Copy Markdown

Thank You!

@younghoandrewchaa

Copy link
Copy Markdown

Thanks!

@anujpradhaan

Copy link
Copy Markdown

You are a savior!

@data-miner00

Copy link
Copy Markdown

Thank you very much!

@GonzaloRMDT

Copy link
Copy Markdown

Thanks!

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