Most if the developers uses Git everyday doing - git init , git add , git commit but very few of them knows how the git actually handle all these commit internally
In this blog , we'll look inside Git , how it works internally , and explore the important role of .git folder
What is Git? ( Quick Recap )
Git is a version control system that helps developer track changes, collaborate and manage project history efficiently.
If you want to know further about Git you can read π this blog too.
Git for Beginners: Basics and Essential Commands
Kunal ' γ» Dec 28 '25
How Git Works (Internal View)
As you know , Git works in three main areas:
1. Working Directory - Your actual project files
2. Staging Area - Where changes are prepared
3. Repository - Where Git permananetly stores snapshot
Everytime you commit , Git :
Takes a snapshot of all tracked files
Stores it safely inside
.gitdirectoryLinks commits together
The Heart of Git : The .git Folder
When you run :
git init
Git creates a hidden folder inside your root folder. Believe me, itβs there β you just canβt see it.
πThis folder is the entire brain of Git
If its deleted, your project is no longer a Git repository
What's inside the .git Folder ?
Lets see whats inside our Git folder π
π You can also see this just simply do
cd .\.git\
ls
Here are the most important parts :
-
objects/- Where Everything is Stored
This folder stores all Git data :
Commits
Files
Directory structures
Note :-
git logshows only commit objects , while.git/objectsstores commit trees and blobs which is why more directories exist than commits
-
refs/- Branch & Tag Pointers
This folder keeps references to:
Branches (
refs/heads) :- Points to the lastest commit of that branchTags (
refs/tags) :- Tags mark a specific commit
Each branch is just a pointer to a commit hash.
-
HEAD- Where you are right now
The HEAD file tells Git :
Which branch you are on
Which commit is currently checked out
-
index- The Staging Area
This file stores :
What you added using
git addWhat will go into the next commit
it acts as a bridge between working directory and repository.
-
config- Repository Settings
Contains :
Remote URLs
User configurations
Repo-specific settings
How a Commit Works Internally
First , we have to look whats inside our commit that makes Git easy to track changes and mark the changes.
Now understand when you run
// Initialize git repository
git init
// Stage changes
git add .
// Commit the staged changes
git commit -m "message"
Git does this :
Initializing git to your repository
git addstores it as a Blob object in.git/objects/git commit -m "message"builds a tree objectNow Git creates a commit object containing π
- Pointer yo the root tree
- Pointer to parent commit
- Author & committer info
- Timestamp
- Commit message
Image credit :- Photo by freeCodeCamp
Final Thoughts
Git may look simple on the surface, but internally its a powerful database . The .git folder is not just a config folder , its the entire history and structure of your project.
Thanks for reading ! if enjoyed this blog , you can read more on this π










Top comments (0)