for i in */; do if [ -d ./$i.git ]; then cd ./$i echo "About to prune branches of $i..." git fetch && git remote prune origin && git branch --merged origin/master | grep -v 'master$' | xargs git branch -D echo "Finished trying to prune branches of $i!" echo " " cd .. fi done echo "Branch pruning complete!"