Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Recursively garbage collect (compress) all child Git repositories from a given base directory.
#!/bin/bash -e
if [[ ! -d $1 ]]; then
echo "Usage: $(basename "$0") DIR"
exit 1
fi
IFS=$'\n'
for gitRepoDir in $(find "$(readlink -f "$1")" -type d -name ".git"); do
gitRepoDir=${gitRepoDir%/.git}
echo
echo
echo "$gitRepoDir"
git --git-dir "$gitRepoDir/.git" gc --aggressive --prune=now
echo
done
unset IFS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.