Last active
March 18, 2021 09:38
-
-
Save eusonlito/3740936be2207b234e0ddf5c97e31460 to your computer and use it in GitHub Desktop.
Clean all git repositories from a base path
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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