Created
August 31, 2011 14:03
-
-
Save zeroasterisk/1183610 to your computer and use it in GitHub Desktop.
git-rmbranch script to facilitate easy branch removal, locally and on 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 | |
# ----------------------------------------------------------- | |
# @requires confirm.sh in the same location as this script | |
# @link http://wuhrr.wordpress.com/2010/01/13/adding-confirmation-to-bash/ | |
# ----------------------------------------------------------- | |
# usage: | |
# git rmbranch branchname [branchname ...] | |
# will force delete N number of branches locally and on origin | |
SCRIPT="$(readlink -nf ${0#./})" | |
SCRIPTNAME="${0##*/}" | |
SCRIPTBASE="${SCRIPT%/*}" | |
source ${SCRIPTBASE}/confirm.sh | |
for branchname in "$@" | |
do | |
if [[ "$branchname" =~ ^(master|test|dev|qa|prod)$ ]] | |
then | |
echo "::Restricted Branch: $branchname -- no action taken::" | |
else | |
confirm "Delete $branchname (y/n)" | |
if [ $? -eq 0 ] | |
then | |
echo "::Deleting branch locally::$branchname" | |
git branch -D "$branchname" && echo "^^done" | |
echo "::Deleting branch on origin::$branchname" | |
git push origin :"$branchname" && echo "^^done" | |
fi | |
fi | |
done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's an example of it being used.. note that the branch "temp-0000-testingD" wasn't on the origin, so git returned an error, but the script just keeps on processing like normal.