Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save arkon108/a0ccd9cc88bb0d100a9fc90ab6f63421 to your computer and use it in GitHub Desktop.
Save arkon108/a0ccd9cc88bb0d100a9fc90ab6f63421 to your computer and use it in GitHub Desktop.
Git remove local branches which were merged
function git-prune-branches() {
echo "switching to master or main branch.."
git branch | grep 'main\|master' | xargs -n 1 git checkout
echo "fetching with -p option...";
git fetch -p;
echo "running pruning of local branches"
git branch -vv | grep ': gone]'| grep -v "\*" | awk '{ print $1; }' | xargs -r git branch -d ;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment