Search code examples
gitgarbage-collection

How to Prevent Garbage Collection in GIT?


Git mysteriously runs Garbage collection "from time to time" and deletes and orphaned commits you have.

https://www.kernel.org/pub/software/scm/git/docs/git-gc.html

Scientifically, this will occur approximately 6-8 hours before you realize you really needed that commit which was just deleted.

I'd rather not have my files deleted by Git. How can I disable automatic garbage collection altogether?


Solution

  • From the very same page you just linked to:

    Some git commands may automatically run git gc; see the --auto flag below for details. If you know what you’re doing and all you want is to disable this behavior permanently without further considerations, just do:

    $ git config --global gc.auto 0