Git garbage collect bash script

by Irish on May 3, 2010

The following shell command will crawl your hard drive, from your current directory, looking for any git repositories. When it finds them it will garbage collect, prune, and pack them, regaining your disk space and make your repositories operate faster.

1
2
#!/bin/sh
find . -type d -name .git | while read dir; do pushd "$dir"; git gc --prune; popd; done

You can run this directly from the terminal or just turn this snippet into a lil bash script file for easy executing later, i.e.

$ touch git_garbage_collect.sh
$ nano git_garbage_collect.sh
$ # copy & paste the script into the file
$ ctrl+o # to save the file
$ ctrl+x # to exit nano

Then just run it like any other bash script

$ ./git_garbage_collect.sh

Need web application development, maintenance for your existing app, or a third party code review?

Velocity Labs can help.

Click here to get started!

Leave a Comment

Previous post:

Next post: