Created
April 23, 2021 18:29
-
-
Save asabla/2df3ac1b2dff834be9781341edf48433 to your computer and use it in GitHub Desktop.
Prune old git branches
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
func_gitprune() { | |
echo 'Starting git prune' | |
echo "Found $(git branch | wc -l) number of local branches" | |
echo "Starts prune of origin branches...." | |
git remote prune origin | |
echo "Local branches which can be removed:" | |
git branch -vv | grep 'origin/.*: gone]' | awk '{print $1}' | |
echo "Pruning local branches..." | |
git branch -vv | grep 'origin/.*: gone]' | awk '{print $1}' | xargs git branch -d | |
echo "$(git branch | wc -l) number of local branches after gitprune" | |
echo "Done!" | |
} | |
# clear no longer tracked git branches (prune) | |
alias gitprune="func_gitprune" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment