Performance
- Git course
- Expert
- Lesson 30/32
- 6 min
Shrink the repository with gc and prune and verify with fsck.
Repository Maintenance and Performance
In large repositories, dangling objects and excessive loose files degrade performance. While git gc (garbage collection) packs loose objects, git prune permanently removes unreachable dangling objects from disk. After maintenance, git fsck (file system check) is executed to verify object integrity and consistency.
git gc --prune=now
git prune
git fsck --fullPractice Optimize Repository with Garbage Collection
Run git gc --prune=now -q in the repository to pack all loose objects and prune old objects. When done, print GC COMPLETED to the terminal.
Starter code
git init -q
git config user.name "Dev"
git config user.email "dev@example.com"
echo "demo" > file.txt
git add file.txt
git commit -m "init" -q
# git gc komutunu çalıştır ve onay mesajını yazdırSample solution
git init -q
git config user.name "Dev"
git config user.email "dev@example.com"
echo "demo" > file.txt
git add file.txt
git commit -m "init" -q
git gc --prune=now -q
echo "GC COMPLETED"Expected output
GC COMPLETED
Practice Verify Repository Integrity with git fsck
Run git fsck --full to verify the entire object database. If the command completes successfully, print FSCK VERIFIED to the terminal.
Starter code
git init -q
git config user.name "Dev"
git config user.email "dev@example.com"
echo "content" > test.txt
git add test.txt
git commit -m "commit 1" -q
# git fsck çalıştır ve başarılı olursa FSCK VERIFIED yazdırSample solution
git init -q
git config user.name "Dev"
git config user.email "dev@example.com"
echo "content" > test.txt
git add test.txt
git commit -m "commit 1" -q
git fsck --full >/dev/null && echo "FSCK VERIFIED"Expected output
FSCK VERIFIED
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Which command pair is used to delete unreachable unreferenced objects from disk and verify the repository?
- git branch -d and git checkout
- git revert and git reset
- git archive and git stash
- git prune and git fsck Correct answer
Explanation: git prune purges objects that are no longer referenced; git fsck inspects the object database to verify there are no corrupt or missing objects.
2 Prune Unreachable Objects Immediately
git gc --prune=____ --quiet
git gc --prune=now --quiet
Explanation: By default git gc purges objects older than two weeks; the --prune=now parameter overrides this window to purge all unreachable objects immediately.
3 Performance and Maintenance Commands
| Term | Meaning |
|---|---|
git gc |
Packs loose objects |
git prune |
Deletes unreachable objects |
git fsck |
Verifies object integrity |
--prune=now |
Cleans old objects immediately |