Interview Prep/Git & GitHub/Git internals: objects, refs and the index

Where does Git store objects on disk, and what are loose objects versus packfiles?

IntermediateConceptGit internals: objects, refs and the index
Answer

Under .git/objects. A loose object is one zlib-compressed file at objects/ab/cdef... named by its ID. When objects pile up, git gc (or git repack) bundles them into objects/pack/*.pack with an .idx index, using delta compression between similar objects. Fetch and push also transfer packfiles.

git count-objects -vH
ls .git/objects/pack
All Git & GitHub questions Roadmap: Git & GitHub

More on Git internals: objects, refs and the index