Last active
May 23, 2019 11:54
-
-
Save zwfang/459cc5347b857fcf293c5c8ab1c219fc to your computer and use it in GitHub Desktop.
Auto clean useless git branch. How effectively remove git branch.
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
#!/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