Skip to content

Instantly share code, notes, and snippets.

@colinhoglund
Created September 8, 2022 00:48
Show Gist options
  • Save colinhoglund/7d569e327625e3ae229ebd54636bc580 to your computer and use it in GitHub Desktop.
Save colinhoglund/7d569e327625e3ae229ebd54636bc580 to your computer and use it in GitHub Desktop.
How To Delete Git Branches
# prune remote branches that no longer exist
git fetch --prune origin
# dry-run list of branches to delete
git push --dry-run --delete origin $(git branch --remotes --merged | grep -vE 'HEAD|master|main' | cut -d\/ -f2- | xargs)
# delete branches
git push --delete origin $(git branch --remotes --merged | grep -vE 'HEAD|master|main' | cut -d\/ -f2- | xargs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment