Skip to content

Instantly share code, notes, and snippets.

@ohlrogge
Last active December 22, 2024 19:35
Show Gist options
  • Save ohlrogge/2d22fd614605ff423c98d12f8b6450f7 to your computer and use it in GitHub Desktop.
Save ohlrogge/2d22fd614605ff423c98d12f8b6450f7 to your computer and use it in GitHub Desktop.
git: Deleting all local branches at once

Sometimes you just want to clean up your local branches after you've pushed everything to orign.

The following command deletes all local branches:

git branch | grep -v main | xargs git branch -d

The single commands in detail:

  • git branch lists all local branches
  • grep -v mainfilters it by all branches except main
  • xargs git branch -d executes the deletion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment