-
-
Save PartyLich/9be71746872bb2ec6a661a7378ebdfba to your computer and use it in GitHub Desktop.
gitclean.sh - cleans merged/stale branches from origin
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 | |
# targetBranch=${2:-$(git rev-parse --abbrev-ref HEAD)} | |
# echo "target branch is '$targetBranch'" | |
remote=${1:-origin} | |
git remote prune $remote | |
# get remote merged branches | |
git branch -r --merged master | \ | |
# remove master or develop case-insensitive | |
egrep -iv '(master|develop|dev)' | \ | |
# replace remote/ with '' (nothing) | |
sed "s/$remote\///g" | \ | |
# use n=1 args with remote branch delete command | |
xargs -n 1 git push --delete $remote |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment