Compressing All Git Repositories On Your Machine
2019 June 27

So I recently felt the need to compress all the git repositories on my machine. This was mainly because I wanted to reduce the number of files I had to wait to backup. So here's the commands I used to make that happen.

DIRS=~
find $DIRS -name '.git' -type d | while read line
do
    pushd $line/..
    git gc --aggressive
    popd
done 

So this just walks over all the directories that contain the magic git data folder, and runs git gc on it. The gc command in git asks for garbage collection and for objects to be packed up into it's actual archive bundle. The pushd and popd commands allow us to end up in the original directory we started at.

In my case I only cared about git repos in my home directory, but you could select any place to run this command.

*****
Written by Henry J Schmale on 2019 June 27