Skip to content

Instantly share code, notes, and snippets.

@MarcelFox
Last active June 21, 2023 20:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarcelFox/ec69ce64bad61cdf37ead0a27d2a3135 to your computer and use it in GitHub Desktop.
Save MarcelFox/ec69ce64bad61cdf37ead0a27d2a3135 to your computer and use it in GitHub Desktop.
Clear local branches safely
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