Last active
April 8, 2021 13:44
-
-
Save shazron/87966896c72e3197f5391b13fd0d7a14 to your computer and use it in GitHub Desktop.
Delete all Greenkeeper 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 | |
# Description: | |
# Delete all `greenkeeper/*` branches of your remote. | |
# Instructions: | |
# Run the script with the `--help` flag. | |
ORIGIN=origin | |
DRY_RUN=0 | |
THIS=`basename "$0"` | |
while test $# -gt 0; do | |
case "$1" in | |
-d|--dry-run) | |
shift | |
DRY_RUN=1 | |
shift | |
;; | |
-h|--help) | |
shift | |
echo "$THIS [REMOTE] [--dry-run]" | |
echo "REMOTE (optional) - the git remote, defaults to 'origin'" | |
echo "--dry-run (optional) - shows what branches that will be deleted," | |
echo " without actually deleting them" | |
echo "--help (optional) - this help message" | |
exit 1 | |
;; | |
*) | |
ORIGIN=${1:-origin} | |
shift | |
;; | |
esac | |
done | |
if [[ $DRY_RUN -eq 1 ]]; then | |
git ls-remote --heads $ORIGIN | sed 's?.*refs/heads/??' | grep "^greenkeeper/" | |
else | |
git ls-remote --heads $ORIGIN | sed 's?.*refs/heads/??' | grep "^greenkeeper/" | xargs -n 1 git push --delete $ORIGIN | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
FYI, I have a GitHub action for it: https://github.com/cometkim/cleankeeper