Skip to content

Instantly share code, notes, and snippets.

@adedayojs
Last active January 25, 2023 07:36
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 adedayojs/f18b69dd9661cd464157231630bcad23 to your computer and use it in GitHub Desktop.
Save adedayojs/f18b69dd9661cd464157231630bcad23 to your computer and use it in GitHub Desktop.
Delete git branch locally
# To delete all branches except for the current branch in one step:
git branch | grep -v $(git rev-parse --abbrev-ref HEAD) | xargs git branch -D
# Delete all branches except a specific branch:
git branch | grep -v "branch name" | xargs git branch -D
# Delete all branches except some specific branch:
git branch | grep -v "branch name" | grep -v "branch name" | xargs git branch -D
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment