Skip to main content

Command Palette

Search for a command to run...

How Git Works & the Role of the .git Folder

Published
2 min read

Why Understand Git Internals

Many beginners memorize Git commands but feel confused when something unexpected happens. Understanding how Git works internally removes fear and helps you fix problems confidently. Git is actually a content storage system before it is a version control tool.

The .git Folder

When you run git init, Git creates a hidden folder called .git inside your project.

This folder is the real database of your project. Your code files are just the working copy.

Everything Git remembers — history, branches, commits, configuration — lives inside this folder.

If you delete .git, your project becomes a normal folder again and all history disappears.

Git Objects

Git stores data as small objects inside .git/objects. There are only three important types.

Blob

Blob represents file content. Only the data — not the filename or folder location.

Tree

Tree represents a folder. It connects filenames to blobs and other trees.

Commit

Commit represents a saved project state. It points to a tree and also links to previous commits forming history.

Relationship

Commit → Tree → Blob

Commit knows the folder structure and files indirectly through trees and blobs.

What Happens During git add

Git reads file content, calculates a hash, and stores it as a blob in .git/objects.

The staging area records which snapshot should become the next commit.

What Happens During git commit

Git creates a tree representing the folder structure, then creates a commit object pointing to that tree.

It also links to the previous commit, forming a chain called history.