Running garbage collection manually
When using Git on a regular basis, you might notice that some commands sometimes trigger Git to perform garbage collection and pack loose objects into a pack file (Git's objects storage). The garbage collection and packing of loose objects can also be triggered manually by executing the git gc
command. Triggering git gc
is useful if you have a lot of loose objects. A loose object can, for example, be a blob, a tree, or a commit. As we saw in Chapter 1, Navigating Git,blob-
, tree-
, and commit
objects are added to Git's database when we add files and create commits. These objects are first stored as unreachable objects in Git's object storage as single files inside the .git/objects
folder. Eventually, or by manual request, Git packs the loose objects into pack files, which can reduce disk usage. A lot of objects can become loose after adding many files to Git, for example, when starting a new project or after frequent adds and commits. Running garbage collection...