Skip to content

Instantly share code, notes, and snippets.

@eusonlito
Last active March 18, 2021 09:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eusonlito/3740936be2207b234e0ddf5c97e31460 to your computer and use it in GitHub Desktop.
Save eusonlito/3740936be2207b234e0ddf5c97e31460 to your computer and use it in GitHub Desktop.
Clean all git repositories from a base path
#!/bin/bash
e () {
echo -e "$(date '+%Y-%m-%d %H:%M:%S'): $1"
}
echo ""
BASE="$1"
if [ "$BASE" == "" ]; then
e "This script require the base path as parameter\n"
exit 1
fi
if [ ! -d "$BASE" ]; then
e "Path $BASE do not exists\n"
exit 1
fi
find "$BASE" -name '.git' -type d 2>/dev/null | while read dir; do
dir="$(dirname "$dir")"
e "Procesing $dir - Before $(du -hs "$dir/.git" | cut -f1)\c"
cd "$dir"
git gc --quiet
git repack -Ad --quiet
git prune
echo " - After $(du -hs "$dir/.git" | cut -f1)"
done
echo ""
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment