It’s all for Your Git Repository be in Top Shape

In previous post, I have introduced that we need do some git housekeeping (git gc) to ensure the repository is in top shape. But I seriously find I have to run the command very often because my colleagues are all very productive. Every time you do a pull, the files in objects folder increase.

So I decided to find a way to ease the housekeeping, and potentially there are two different ways to do so.

Windows Scheduler

The first way came to my mind is to use Windows Scheduler. You can create a bash file for cleaning the repository. Within the bash file there are some line of commands look like this

cd D:\Sources\\Source
git gc

And then create a scheduler to execute the bash file, specify the time you would like it to be executed.


Git Hooks

Hook is so lovely no matter in which sort of version control tool because it provides the opportunities for you to handle different events.

We can use hook to run the housekeeping after each git commit. To do that, you need go to the folder $Repository/.git/hooks/ and create a text file named post-commit

In that file, the content looks like this

git gc

And it’s done.

After the recipe applied, I only encounter only few times of Visual Studio crashing. One thing I want to mention finally is that git gc tries very hard to be safe about the garbage it collects. (


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s