Inside Git: How It Works and the Role of the .git Folder
What is .git Folder?
When you run git init, Git creates a hidden .git folder.
This folder stores all history, commits, and data.
If itβs deleted β your repo is gone.
.git = Gitβs database
Inside .git (Simplified)
.git/
β
βββ objects/ β Stores all file data (blobs, trees, commits)
βββ refs/ β Branch pointers
βββ HEAD β Current branch
βββ index β Staging area
βββ config β Repo settings
Mental Model
.git = Database where Git stores everythin
1. Blob (File Content)
A blob stores:
β
Only file data
β No filename
Example:
hello.txt β "Hi World"
Git saves:
Blob = "Hi World"
If 2 files have same content β Git stores only ONE blob (saves space )
πΉ 2. Tree (Folder Structure)
A tree stores:
β
Folder info
β
File names
β
Links to blobs
Example:
project/
ββ app.js
ββ index.html
Tree connects:
Tree
βββ app.js β Blob
βββ index.html β Blob
Think of Tree = Folder snapshot π
πΉ 3. Commit (Snapshot Record πΈ)
A commit stores:
β
Pointer to Tree
β
Author
β
Date
β
Message
β
Parent commit
Commit
β
Tree
β
Blobs
Each commit = Full snapshot of project
How Git Tracks Changes
Git doesnβt save only differences.
It saves snapshots of files.
Same files = reused (no extra space).
So Git is fast and efficient.
What Happens in git add?
git add file.txt
β Creates a blob
β Puts it in staging area (index)
Files β Staging Area
What Happens in git commit?
git commit -m "msg"
β Creates tree
β Creates commit
β Moves branch forward
Staging β Commit β Branch
How Git Uses Hashes
Every object has a unique hash.
π If data changes β hash changes
π Keeps Git secure and reliable π
Summary
.git= main storageBlob = file
Tree = folder
Commit = snapshot
add= preparecommit= save