Skip to content

Instantly share code, notes, and snippets.

@JsAndDotNet
Created September 9, 2021 08:59
Show Gist options
  • Save JsAndDotNet/4835e9c83922807ac711a01fb90988de to your computer and use it in GitHub Desktop.
Save JsAndDotNet/4835e9c83922807ac711a01fb90988de to your computer and use it in GitHub Desktop.
Delete All Branches Except Master Windows
#The command to delete all branches except master on linux is:
#git branch | grep -v "master" | xargs git branch -D
#To use the same command in Windows use powershell and CD to your repo
#Or, WINDOWS - we can use PowerShell command that do the same thing that above command do:
# Tried this and it worked nicely...
git branch | %{ $_.Trim() } | ?{ $_ -ne 'master' } | %{ git branch -D $_ }
#or WINDOWS -
#git branch -D @(git branch | select-string -NotMatch "master" | Foreach {$_.Line.Trim()})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment