Last active
June 21, 2023 20:22
-
-
Save MarcelFox/ec69ce64bad61cdf37ead0a27d2a3135 to your computer and use it in GitHub Desktop.
Clear local branches safely
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
clear_branches() { | |
GIT_DIR=".git" | |
BRANCH_EXIST=$(git branch | awk '!/\*/ && !/main/ && !/development/ && !/staging/ && !/develop/ && !/master/') | |
if [[ ! -d "$GIT_DIR" ]]; | |
then | |
echo "directory $GIT_DIR not found" | |
return | |
fi; | |
if [[ $BRANCH_EXIST == '' ]]; | |
then | |
echo 'Did not found any local branchs that are safe to be removed'; | |
return | |
fi | |
git remote prune origin; | |
git branch | awk '!/\*/ && !/main/ && !/development/ && !/staging/ && !/develop/ && !/master/ {print $1}' | xargs git branch -D | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment