This is a simple script that I use to remove local branches that are no longer on the origin. Just to clean my local env.
git remote prune origin
git branch -vv | grep ': gone]' | grep -v "\*" | awk '{ print $1; }' | xargs -r git branch -d
You can also create an alias and add to your .bashrc (if you use Linux or macOS).
Edit ~/.bashrc file.
Add this in the end of the file:
alias git-clean="git remote prune origin; git branch -vv | grep ': gone]' | grep -v \"\*\" | awk '{ print $1; }' | xargs -r git branch -d;"
Reload bash: source ~/.bashrc
That's all. :)
Top comments (0)