The Object Database
What
At its core, Git is a simple content-addressable key-value database. The database is stored locally inside your project’s hidden .git/objects directory. All version-controlled data—including commits, folders, and files—is stored in this directory as Git “objects.”
How
Every object stored in Git is given a key, which is the 40-character SHA-1 hash of its content. To avoid slowing down file system lookups by putting thousands of files in a single folder, Git splits the 40-character hash:
- The first 2 characters become a subdirectory name under
.git/objects/. - The remaining 38 characters become the filename of the object inside that subdirectory.
# If a commit hash is 5ba786fcc93e8092831c01e71444b9baa2228a4f:
# It will be stored at the following path:
.git/objects/5b/a786fcc93e8092831c01e71444b9baa2228a4f
Why
Storing everything as unique content-hashed files makes Git extremely fast, simple, and reliable. Because the name of each file is tied directly to its exact content, Git doesn’t need complex tables or indexes to retrieve files; it simply reads the file corresponding to the hash key.
Summary
Git’s database is a simple content-addressable key-value store stored in .git/objects/, where objects are organized into subdirectories named after the first two characters of their SHA-1 hashes.