Inside Git: How It Works and the Role of the .git Folder
A Closer Look at How Git Tracks Your Code's History, Branches, and Changes

Software engineer passionate about tech, innovation & research. I explore, build, and share insights on coding, systems, and emerging technologies.
How Git Works Internally
Git may look complicated at first, but internally it works in a very logical and organized way. Instead of just saving files, Git carefully tracks changes and stores them in a structured system. Understanding this helps you use Git with confidence, not by memorizing commands but by knowing what is really happening.
Understanding the .git Folder
The .git folder is the heart of any Git repository. When you run git init, Git creates this hidden folder. It contains everything Git needs to track your project.
Inside the .git folder, Git stores:
All versions of your files
History of commits
Information about branches
Details about who made changes and when
If the .git folder is deleted, the project is no longer a Git repository. That is why this folder exists to safely store the complete history and structure of your project.
Git Objects: Blob, Tree, and Commit
Git stores data using three main objects. These objects help Git track changes efficiently.
Blob (File Content)
A blob stores the content of a file. It does not store the file name, only the data inside the file. If the file content does not change, Git reuses the same blob.
Tree (Folder Structure)
A tree represents a directory. It connects file names to blobs and can also point to other trees. This is how Git remembers the folder structure of your project.
Commit (Snapshot)
A commit is like a snapshot of your project at a specific time. It points to a tree and also stores:
Commit message
Author information
Time of commit
Reference to the previous commit
Together, blobs, trees, and commits form the complete history of your project.
How Git Tracks Changes
Git does not track changes line by line like a normal editor. Instead, it stores snapshots. When a file changes, Git creates a new blob for that file and connects it to a new tree and commit.
If a file does not change, Git simply points to the old blob. This makes Git fast and saves storage space.
What Happens During git add
When you run git add, Git:
Takes the current version of the file
Creates a blob for its content
Stores it inside the .git folder
Places it in the staging area
The staging area is like a waiting room where Git prepares files for commit.
What Happens During git commit
When you run git commit, Git:
Creates a tree from the staged files
Creates a commit object
Links it to the previous commit
Saves it permanently in the repository history
This is how Git builds a chain of commits over time.
How Git Uses Hashes
Git uses hashes (SHA‑1) to identify objects. Every blob, tree, and commit has a unique hash value.
These hashes help Git:
Ensure data integrity
Detect file changes
Avoid duplicate storage
If even one character changes in a file, the hash changes completely. This makes Git very reliable and secure.
Building a Mental Model of Git
Instead of thinking of Git as just commands, think of it as a storage system:
Files become blobs
Folders become trees
Project states become commits
Commands like git add and git commit simply move data through this system. Once you understand this flow, Git becomes much easier to use.




