Inside Git: How It Works and the Role of the .git Folder
What's stored within the .git folder?

Introduction
Let me be honest when I first started using Git, I was just blindly following commands:
git init
git add .
git commit -m "First commit"
In this blog, Iβll break down what happens under the hood how Git stores your files, what lives inside the .git folder, and how Git tracks your changes using blobs, trees, and commits.
π What is the .git Folder?
The .git folder is created the moment you run:
git init
This hidden directory is where Git stores all version control data. Think of it as the brain of Git.
Without this folder, Git has no memory of your commits, branches, or file history.
.git Folder Structure

Key Parts:
HEAD: Points to your current branchobjects/: Contains all actual content, hashed and compressedrefs/heads/: Contains your branch references
Git Objects: Blob, Tree, and Commit
Git stores data as objects. There are 3 main types:
1. Blob (Binary Large Object)
Stores the content of a file.
Doesnβt care about filename, just the content.
Example:
If you write Hello World in file.txt, Git saves that content as a blob and gives it a unique hash.
2. Tree
Represents folders or directory structures.
Stores filenames and links them to blob hashes.
Example:
A tree might say:
file.txtβ points to blobabc123about/β points to another tree
3. Commit
A snapshot of the entire project at a specific point in time.
Stores:
A pointer to the tree
A commit message
Author info
A pointer to the previous commit
Commit β Tree β Blob Structure
Visualize this like a linked chain:

How Git Tracks Changes
Unlike some version control systems that store diffs, Git stores complete snapshots.
When you commit, Git doesnβt say βthis line changedβ - it says:
βHereβs the full state of the project right now, and hereβs what changed compared to the previous commit.β
This is made possible by the content-addressed system using SHA-1 hashes.
What Happens When You Run git add?
Letβs say you run:
git add index.html
Hereβs what Git does internally:
Takes the content of
index.htmlCreates a blob object for it
Adds an entry to the staging area (aka index) to mark it for commit
Note: Git doesnβt care about file names at this point only content!
What Happens When You Run git commit?
Letβs say you run:
git commit -m "Add homepage"
Git performs 3 actions:
Takes the files in the staging area
Creates a tree object
Creates a commit object, linking to:
the tree
the previous commit
the message and author
Updates the branch (like
main) to point to this new commit
Git Workflow (Add β Commit)
Hereβs how the process flows:

Git Hashes: The Backbone of Git
Everything Git stores is hashed using SHA-1.
For example, this:
git hash-object index.html
β¦might return:
e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
This means Git is saving content by its hash not file name.
Why is this awesome?
Ensures data integrity
Detects even the tiniest changes
Prevents duplication




