-
-
Save shazron/87966896c72e3197f5391b13fd0d7a14 to your computer and use it in GitHub Desktop.
#!/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 |
π
π
Probably you will end up searching for it anyway:
bash <(curl -s https://gist.githubusercontent.com/shazron/87966896c72e3197f5391b13fd0d7a14/raw/676392bed7ce4f246c7b8edba1312741cfbed61b/delete_all_greenkeeper_branches.sh)
Copy paste to run this script directly from url.
I recommend people stumbling across this to run the command without the last xargs pipe first, just to get a glance of which branches would potentially be affected (there is no easy way to reverse this as far as I'm concerned). For somebody with 300+ branches to clean up in order to remove and replace greenkeeper, this is a real life-saver. Thanks π
@steffenz I updated the script with a --dry-run
option
Wow - that's awesome π Wasn't expecting a fix at all, but it is definitely highly appreciated. Thanks for sharing, and making it even better π You saved me a lot of time!
FYI, I have a GitHub action for it: https://github.com/cometkim/cleankeeper
π Nice :)
π