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 will make sure that loose objects are packed, and objects not referred to by any reference or object will be deleted. The latter is useful when you have deleted some branches/commits and want to make sure that the objects referenced by them are also deleted.

Let's see how we can trigger garbage collection and remove some objects from the database.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.42.94