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.
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
D: cd D:\Sources\CE.com\Source git gc
And then create a scheduler to execute the bash file, specify the time you would like it to be executed.
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
#!/bin/sh 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. (http://www.kernel.org/pub/software/scm/git/docs/git-gc.html)