Introduction
Git stores many objects as you work, like commits and files. Over time, some objects become unused and take up space. The git gc command cleans up these unused objects to keep your repository fast and small.
When your repository feels slow or large after many commits and branches.
When you want to free up disk space used by old, unneeded data in your git repository.
After deleting branches or rewriting history to remove old commits.
Before making a backup to reduce the size of the repository.
When git suggests running garbage collection to optimize performance.