Last active
May 2, 2022 05:19
-
-
Save benfortuna/45f51efc6f441eb0ab771af8bb208994 to your computer and use it in GitHub Desktop.
Cleanup stale git branches
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# list merged branches | |
BRANCHES=`git branch -r --merged | grep -v "*" | grep -v master | grep -v develop | grep -v release/ | grep -v hotfix/ | sed 's/origin\///'` | |
printf "Removing branches: \n$BRANCHES" | |
# delete all remote branches merged into the current branch (i.e. develop), excluding release/master/develop branches | |
git branch -r --merged | grep -v "*" | grep -v master | grep -v develop | grep -v release/ | grep -v hotfix/ | sed 's/origin\///' | xargs -n 1 git push --delete origin |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment