Forrest logo
back to the git tool

git-gc:tldr:8dc59

git-gc: Do not prune loose objects (prunes by default).
$ git gc --no-prune
try on your machine

The git gc command stands for "git garbage collection" and is used to optimize and clean up unnecessary objects in the Git repository. By default, git gc will also prune (remove) unreachable objects, i.e., objects that are no longer referenced by any branch or tag.

However, when the --no-prune option is passed to the git gc command, it instructs Git not to remove these unreachable objects during garbage collection. This means that unused or unreachable objects will still be retained in the repository even after garbage collection.

Although not pruning the unreachable objects might consume some extra space in the repository, it can be useful in certain situations. For example, if you suspect that some objects might have become unreachable due to a mistake or an incomplete operation, you can use git gc --no-prune to prevent accidental deletion and preserve those objects for further examination or recovery.

It's important to note that using git gc --no-prune regularly without a specific reason can lead to a bloated repository and unnecessary disk space usage. Therefore, it's generally recommended to let git gc perform pruning to keep the repository efficient and optimized.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the git tool