Skip to content

Instantly share code, notes, and snippets.

@magnetikonline
Last active October 2, 2023 13:38
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save magnetikonline/4064851 to your computer and use it in GitHub Desktop.
Save magnetikonline/4064851 to your computer and use it in GitHub Desktop.
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