Most developers use Git every day, doing - git init , git add, git commit but very few of them know how git actually handles all these commits internally
In this blog, we will look inside Git , how it works internally, and explore the important role of the .git folder
What is Git? (Quick Recap)
Git is a version control system that helps developers track changes, collaborate, and manage project history efficiently.
If you want to learn more 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 permanently stores snapshot
Every time you commit, Git :
Takes a snapshot of all tracked files
Stores it safely inside the
.gitdirectoryLinks commits together
The Heart of Git: The .git Folder
When you run:
git init
Git creates a hidden folder inside the root folder. Believe me, itโs thereโyou just canโt see it.
๐This folder is the entire brain of Git.
If it's deleted, your project is no longer a Git repository.
What's inside the .git Folder?
Lets see what's inside our Git folder ๐
๐ You can also see this-just 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 latest 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 the working directory and the repository.
-
configโ Repository Settings
Contains:
Remote URLs
User configurations
Repo-specific settings
How a Commit Works Internally
First, we have to look at what's inside our commit that makes Git easy to track and mark changes.
Now, understand when you run
// Initialize a Git repository
git init
// Stage changes
git add .
// Commit the staged changes
git commit -m "message"
Git does this:
Initializing git in 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 to the root tree
- Pointer to the 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)