I have turned off git's annoying automatic repacking functionality (I guess that most git-users know the "repacking for optimal performance" message when working with git) and am instead invoking "git gc" overnight with a cronjob.
However I am unsure if that is enough and whether I should also run "git repack" before or after "git gc".
The manpages of "git repack" and "git gc" don't mention any connection between the two, and the manpage of "git repack" actually contains this phrase:
Instead, the loose unreachable objects will be pruned according to normal expiry rules with the next git gc invocation.
This would indicate to me that "git gc" is not sufficient for all house-keeping tasks and "git repack" is also needed. Is that correct and what housekeeping-commands should be used for git?
The git gc command is a repository maintenance command. The "gc" stands for garbage collection. Executing git gc is literally telling Git to clean up the mess it's made in the current repository. Garbage collection is a concept that originates from interpreted programming languages which do dynamic memory allocation.
Running git gc manually should only be needed when adding objects to a repository without regularly running such porcelain commands, to do a one-off repository optimization, or e.g. to clean up a suboptimal mass-import.
The git gc command cleans up unnecessary files and optimizes the local repository. GitHub runs this operation on its hosted repositories automatically on a regular basis based on a variety of triggers. Locally you can run it at any time. Running it won't have any adverse effect on your repository.
When you do a Git clone, it will create a copy of the whole repository, this includes the pack file as this is part of the repo too. The only way to reduce the size of the pack file will be by removing contents from your repo.
git repack
just repacks the objects.
git gc
repacks them and throws away the old unreachable objects.
To verify you can do something like find .git/objects
before and after git gc
: before you should see all new objects as separate files. Afterwards there should be only one big pack file.
For details you can also have a look at the code: In builtin/gc.c the repack command is prepared and executed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With