#!/bin/bash function repos_update_clean() { # Make sure directory exists if [ ! -d "${1}" ]; then return fi # Update only git repos if [ ! -d "${1}/.git" ]; then return fi echo "Updating repos: ${1}" pushd "${1}" 1> /dev/null git remote update git gc --aggressive # Iterate over all remotes and clean (prune) for r in $(git remote); do echo " Cleaning remote: ${r}" git remote prune ${r} done popd 1> /dev/null } export -f repos_update_clean find . -maxdepth 1 -type d -exec bash -c 'repos_update_clean "$0"' {} \;