Skip to content

Instantly share code, notes, and snippets.

@lomholdt
Last active September 8, 2021 09:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lomholdt/c45b24ec036dbd62322623abf9036c66 to your computer and use it in GitHub Desktop.
Save lomholdt/c45b24ec036dbd62322623abf9036c66 to your computer and use it in GitHub Desktop.
Remove all git branches besides master and the current in powershell
function Remove-AllGitBranches {
,@(git branch | Select-String -Pattern "((\*\s)?master|main)|(\*\s).+" -NotMatch) | ForEach-Object{$_.Line.Trim()} | ForEach-Object{git branch -D $_}
}
@lomholdt
Copy link
Author

lomholdt commented Oct 3, 2018

This is a Powershell command to delete all git branches besides the master and the one you are currently on.

@lomholdt
Copy link
Author

lomholdt commented Sep 8, 2021

Updated to include main branch.

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