⚡ ~/naveed Interview Prep
⚡ Portfolio Home ✍️ Engineering Blog Deep Dives 🎯 Interview Hub 998+ Scenarios ☸️ Kubernetes Mastery Hub 24 Modules 🎮 DevOps Arcade & Quizzes Subnet Blitz ⚡ 🗺️ DevOps Roadmaps PDFs & Guides 🤖 Morpheus Analysis AI Quant ↗ 🛠️ Developer Tools Utilities 🧪 Labs & Experiments 📄 Interactive CV & Certs 🔗 All Links & Socials ⚡ Join The Dispatch (Weekly SRE Newsletter) →
Senior DevOps / SRE [L2] Git Amend without editing message Production Scenario [L2]

Q: What does `git gc` do, and when should you run it manually?

git gc (garbage collection) performs housekeeping on the Git object database:

#Git #Amend without editing message #L2 #Version Control #Collaboration #Rebase
🎙️ Candidate Opening & Architectural Context
""In a fast-paced team with dozens of pull requests merged daily, Git workflow hygiene was critical. The interviewer is testing: Understanding of Git's garbage collection and object packing.. I structure my answer around systematic triage first, root cause analysis second, and permanent remediation third.""
Advertisement

🛠️ Production Runbook & Step-by-Step Resolution

1️⃣

Initial Diagnostics & Root Cause Analysis

git gc (garbage collection) performs housekeeping on the Git object database:

  • Packs loose objects into packfiles — individual objects in .git/objects/ are compressed into efficient .pack files with delta compression.
  • Removes unreachable objects — commits, blobs, and trees that no ref (branch, tag, reflog) points to. These are typically from amended commits, rebases, or deleted branches.
  • Packs refs — consolidates individual ref files in .git/refs/ into a single packed-refs file.
  • Prunes old reflog entries — entries older than 90 days (reachable) or 30 days (unreachable) by default.
2️⃣

Remediation & Permanent Safeguards

When Git runs it automatically: Git triggers gc --auto after certain operations (e.g., when there are more than 6700 loose objects or more than 50 packfiles). You rarely need to run it manually. When to run manually: Aggressive GC: This spends more CPU time on delta compression for a smaller packfile. Only useful occasionally (e.g., after importing from another VCS). Don't run it routinely — the default compression is good enough and --aggressive is slow. Caution: --prune=now immediately deletes unreachable objects. If you're recovering lost commits via reflog, run recovery *before* GC.

git gc --aggressive --prune=now
  • After large history rewrites (filter-repo, mass deletions) to reclaim disk space.
  • When the repo feels slow and .git/ is unusually large.
  • Before creating a bundle or archive — ensures maximum compression.
💡 The Senior SRE Gold Nugget (Key Architectural Takeaway)
"Pro-Tip: Packs loose objects into packfiles — individual objects in .git/objects/ are compressed into efficient .pack files with delta comp."
⚡ 60-Second Elevator Pitch Talking Points
  • Packs loose objects into packfiles — individual objects in .git/objects/ are compressed into effi...
  • Removes unreachable objects — commits, blobs, and trees that no ref (branch, tag, reflog) points ...
  • Packs refs — consolidates individual ref files in .git/refs/ into a single packed-refs file.
Advertisement
Want more Git scenarios?
Explore our complete collection of scenario-based Git interview runbooks.
Browse All Git Questions →

📚 Related Production Scenarios in Git