Skip to content

Instantly share code, notes, and snippets.

@zwfang
Last active May 23, 2019 11:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zwfang/459cc5347b857fcf293c5c8ab1c219fc to your computer and use it in GitHub Desktop.
Save zwfang/459cc5347b857fcf293c5c8ab1c219fc to your computer and use it in GitHub Desktop.
Auto clean useless git branch. How effectively remove git branch.
#!/usr/bin/env bash
#----------------------------------------------------------------------------------
# author: Andy
# feature: clean useless git-branch,
# but master, current branch, other branch you passed in command line
# usage: bash auto_remote_local_git_branch.bash branch branch branch is you don't want remove
#----------------------------------------------------------------------------------
echo -e "begin...\n"
for branch in `git branch --format="%(refname:short)"` ; do
if [[ $* =~ ${branch} || ${branch} == "master" || ${branch} == `git rev-parse --abbrev-ref HEAD` ]] ; then
echo "retained branch ${branch}";
else
git branch -D ${branch};
# git push origin :${branch};
fi
done
echo -e "\ndone..."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment