Skip to content

Instantly share code, notes, and snippets.

@mohokh67
Created January 14, 2020 11:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mohokh67/419f05cca125c8e89b54947b3b7f6bb4 to your computer and use it in GitHub Desktop.
Save mohokh67/419f05cca125c8e89b54947b3b7f6bb4 to your computer and use it in GitHub Desktop.
Git: Remove all branches except master

Git

Remove all local branches except master

This example will show how to remove all Git branches in local except master branch

git branch | grep -v "master" | xargs git branch -D

Keep master with another one, remove the rest

If you would like to keep master and another-branch then run this:

git branch | grep -v "master\|another-branch" | xargs git branch -D
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment