Last active
August 15, 2019 16:38
-
-
Save someguynamedmatt/211151c4405718e1a1f8dbdf56e76788 to your computer and use it in GitHub Desktop.
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 - | |
#=============================================================================== | |
# | |
# FILE: branch_clean.sh | |
# | |
# USAGE: ./branch_clean.sh | |
# | |
# DESCRIPTION: Go through your local git branches one-by-one and do a local delete | |
# of what you want. This will purposely skip master and release. | |
# | |
# OPTIONS: --- | |
# REQUIREMENTS: --- | |
# BUGS: --- | |
# NOTES: --- | |
# AUTHOR: Matt <[email protected]> | |
# ORGANIZATION: | |
# CREATED: 04/25/2018 18:10 | |
# REVISION: 1.2 | |
#=============================================================================== | |
#set -o nounset # Treat unset variables as an error | |
set -f | |
RED='\033[0;31m' | |
GREEN='\033[0;32m' | |
NORMAL='\033[0m' | |
YELLOW='\033[0;33m' | |
echo "*****************************************" | |
echo -e "${GREEN}Git branch cleaner.${NORMAL}" | |
echo "*****************************************" | |
printf "Iterating through your ${GREEN}$1${NORMAL} branches." | |
printf '\n\n' | |
cd $1 | |
BRANCHES=$(git branch | grep -v "master\|release") | |
for branch in $BRANCHES | |
do | |
if [[ "$branch" != "*" ]]; then | |
printf "Locally delete ${YELLOW}${branch}${NORMAL} (select r if you want to remote delete as well)? (y/n/r) " | |
read -n1 answer | |
printf '\n' | |
if [[ $answer == "y" ]]; then | |
"$(git branch -D ${branch})" > /dev/null 2>&1 | |
fi | |
if [[ $answer == "r" ]]; then | |
"$(git push origin --delete ${branch})" > /dev/null 2>&1 | |
fi | |
fi | |
done | |
printf 'All clean!\n' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment