Skip to main content
In this lesson, we dive into Git’s internal mechanisms, explaining how Git uses a key-value store model to manage files. Each file added to a commit is hashed using the SHA-1 algorithm, and the resulting hash uniquely identifies the folder where the file’s contents are stored. Git commands are divided into two main categories:
  • Porcelain Commands: These are user-friendly commands such as git add, git status, git commit, and git stash.
  • Plumbing Commands: These commands, including git hash-object and git cat-file, allow you to interact directly with Git’s internal data structures.
Below is an overview of these commands:
Using plumbing commands, you can compute the hash that Git uses internally. This process is similar to what happens when you run git commit. For example, suppose you have a file named first_story.txt containing a short sentence. First, add some content to the file:
Next, generate a SHA-1 hash for this file using the following command. Notice how Git returns a hash value where the first two characters indicate the folder in which the content is stored:
If you commit the first_story.txt file, Git will generate the same hash:
Git then creates a folder using the first two characters of the hash—in this case, “be”. You can inspect the internal Git structure by navigating to the .git folder, which is created when you run git init. For instance, after adding and committing the file, you might see:
To view the content corresponding to a particular hash, use the plumbing command git cat-file with the -p flag for pretty-printing:
For example, using the first part of the hash:
When you inspect a commit object, Git includes additional metadata along with the file content. Consider the following example:
This commit object contains:
  • A tree reference that points to the repository’s folder structure.
  • A parent commit reference.
  • Author information indicating who made the changes.
  • Committer details showing who committed the changes.
Next, let’s discuss Git’s object types. Git organizes its internal storage into three primary object types: When you make multiple commits, Git builds a structure where each commit points to its parent. Each commit references trees (representing directory structures) and blobs (file data). For example, the first commit might reference a blob for first_story.txt, and a subsequent commit might reference both the previous blob and a new blob for another file.
The image shows a commit history with three entries by @sarah, detailing additions and changes to stories, each with unique commit hashes.
Every commit acts as a snapshot of the repository, linking together trees and blobs to facilitate powerful version control features. That concludes our lesson on how Git works internally. Stay tuned for the next lesson as we continue to explore Git’s capabilities and best practices!

Watch Video