git gc
- Git course
- Expert
- Lesson 17/32
- 4 min
Learn repository cleanup with git gc.
Repository cleanup with git gc
git gc (garbage collection) helps use repository storage more efficiently by organizing Git objects. It can combine loose objects into pack files and clean up unnecessary data.
git gcGit can also perform some maintenance tasks automatically. You can run git gc manually when repository maintenance is needed.
Packing and maintenance options
Git objects can initially be stored as separate files. Packing these files over time can improve storage and access efficiency.
git gc --auto
git gc --aggressive--auto allows Git to perform maintenance when needed. --aggressive performs a more intensive packing operation and may take longer.
Practice Run the git gc maintenance command
Run garbage collection in the repository using the automatic maintenance option. Then print a message indicating that the operation is complete.
Starter code
# Otomatik depo bakımını çalıştır
# Tamamlanma mesajını yazdırSample solution
git gc --auto
echo 'Depo bakımı tamamlandı'Expected output
Depo bakımı tamamlandı
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 You want to improve storage usage by packing loose objects in a repository. Which command performs this maintenance task?
- git status
- git diff
- git fsck
- git gc Correct answer
Explanation: <code>git gc</code> performs repository maintenance by packing objects and cleaning up unnecessary data.
2 Complete the automatic maintenance option
git gc ____
git gc --auto
Explanation: The <code>--auto</code> option allows Git to run garbage collection when maintenance is needed.
3 Git gc concepts
| Term | Meaning |
|---|---|
git gc |
Organizes repository objects |
Garbage collection |
Cleaning up unnecessary data |
Pack dosyası |
Stores objects together |
--aggressive |
Performs more intensive packing |