Skip to content

Instantly share code, notes, and snippets.

@bricss
Last active February 17, 2023 17:16
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 bricss/dc19e73b05bf6e5a2cd1c0457aa489f2 to your computer and use it in GitHub Desktop.
Save bricss/dc19e73b05bf6e5a2cd1c0457aa489f2 to your computer and use it in GitHub Desktop.
Remove remote merged branches from Git repo
#!/usr/bin/env bash
# Removes remote merged branches from Git repo
# Usage: `sh git-broom.sh`
protect='(dev|main|master|release)'
git fetch --prune --tags origin
git branch --remotes --merged origin | grep origin | grep -v $(git symbolic-ref --short HEAD) | egrep -v $protect | sed s/origin\\/// | xargs git push origin --delete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment