Last active
September 9, 2016 18:07
-
-
Save borgateo/2155b17c61a9bd6362a9318d610cadcc to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
set -e | |
# Note: | |
# run this script from the project folder | |
# `sh /path/delete-branches.sh` | |
# Some Colors | |
red=`tput setaf 1` | |
green=`tput setaf 2` | |
reset=`tput sgr0` | |
# Regular Expression to grep only the following branches | |
BRANCHES='[Rr][Ee][Dd]-201605' | |
#'red-201605' | |
function branchesList { | |
git branch -r --merged | \ | |
grep origin | \ | |
grep -v '>' | \ | |
grep -v master | \ | |
grep $BRANCHES | |
} | |
function deleteBrances { | |
git branch -r --merged | \ | |
grep origin | \ | |
grep -v '>' | \ | |
grep -v master | \ | |
grep $BRANCHES | \ | |
xargs -L1 | \ | |
cut -d"/" -f2- | \ | |
xargs git push origin --delete | |
git fetch --all --prune | |
} | |
function prompt { | |
echo "${green}Do you want to delete these branches? (y/N)${reset}" | |
read answer | |
if echo "$answer" | grep -iq "^y" ;then | |
deleteBrances | |
else | |
echo "Okey dokey! see you later alligator 😉 "; echo | |
exit | |
fi | |
} | |
############## | |
branchesList | |
prompt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment