In this article I describe my approach to keeping the disk space for my Git repositories low on both the desktop and netbook machine.
I use Git to track changes in my code and files. I keep my Git repositories in ~/GIT and other people's repositories in ~/Source/ or ~/Projects.
Git by default keeps objects lying around for a while: when you delete a branch forcibly, with changes/commits which are no longer reachable by any HEAD, Git will by default keep those references around for a while, until git gc is invoked, usually automatically.
Since the disk space on my netbook is usually low, I keep around a small script to help me manage it by routinely garbage-collecting all the repositories.
The script resides in ~/bin, which I have added to the $PATH. Its name is git-repack-all, and can therefore be invoked via git repack-all from any directory.
The script simply goes through all the .git directories in any of the current directory's subdirectories, and launches git gc on these directories.
#!/bin/bash
find . -type d -name '.git' -print0 | \
xargs -0 -P4 -I{} sh -c 'cd {}; git gc >/dev/null 2>&1 ; echo done {}'
I simply launch it both on ~/GIT and ~/Source or ~/Projects, and go my merry way.
blog comments powered by Disqus