Skip to main content

Command Palette

Search for a command to run...

How Git Works Internally ☕

Discovering the Inner Workings of Git with a Chai Twist

Updated
4 min read
How Git Works Internally ☕

So far, we’ve treated Git like a chai recipe book.
Now let’s open that book and see how Git actually stores everything inside.

Don’t worry no scary internals.
We’ll understand Git the same way we understand chai.

The .git Folder: Git’s Secret Kitchen

When you run:

git init

Git creates a hidden folder called:

.git/

This folder is Git itself.

Important rule:❗ If .git is deleted, your entire Git history is gone.

Chai Analogy ☕

Think of:

  • Your project folder → Chai Stall

  • .git folder → Locked Recipe Room

Customers see the stall,
but only you access the recipe room.

Why the .git Folder Exists

The .git folder stores:

  • Every chai recipe you ever approved

  • Every experiment you tried

  • Every branch

  • The full history of changes

That’s why Git can:

  • Go back in time

  • Compare versions

  • Undo mistakes safely

.git Folder Structure

Conceptually, .git looks like this:

.git/
 ├── objects/    → actual data (recipes)
 ├── refs/       → branches
 ├── HEAD        → current position
 ├── index       → staging area
 └── config      → settings

Let’s now understand what Git stores inside objects/.

Git Objects: The Three Building Blocks ☕

Git stores everything using three object types:

  1. Blob

  2. Tree

  3. Commit

Think of them as ingredients, recipes, and recipe entries.

Blob – The Ingredients

A blob stores:

  • The content of a file

  • Nothing else

No filename,No folder name Just raw data

Chai Analogy

A blob is like:→ Sugar, tea leaves, ginger — stored separately

Git doesn’t care where the ingredient is used,
only what it is.

Tree – The Recipe Structure

A tree object:

  • Connects blobs together

  • Stores folder structure

  • Maps filenames to blobs

Chai Analogy

A tree is like:→ “This recipe uses sugar + ginger + tea leaves”

It doesn’t store ingredients itself it points to them.

Example

Recipe:
 ├── sugar (blob)
 ├── tea (blob)
 └── ginger (blob)

Commit – The Saved Recipe Entry

A commit is the final, approved recipe.

It contains:

  • A reference to a tree

  • Author info

  • Timestamp

  • Commit message

  • Parent commit (previous recipe)

Chai Analogy

A commit is like writing:→“On Monday, we approved this chai recipe because customers loved it.”

It doesn’t store ingredients directly it points to the recipe structure (tree).

What Happens During git add

Now let’s see what Git actually does internally.

git add Explained (Chai Style)

Command:

git add .

What Git does:

  1. Reads file content

  2. Converts content into blobs

  3. Stores blobs inside .git/objects

  4. Updates the index (staging area)

Chai Analogy

You:

  • Prepare chai

  • Taste it

  • Place the recipe on the taste table

Nothing is saved permanently yet.

git add Flow

Working Directory
        ↓
     git add
        ↓
 Staging Area (Index)

What Happens During git commit

Command:

git commit -m "Perfect chai balance"

Internally Git:

  1. Takes staged blobs

  2. Creates a tree

  3. Creates a commit pointing to that tree

  4. Moves HEAD to the new commit

Chai Analogy

You:

  • Take approved recipe

  • Write it in the recipe book

  • Mark it as the latest version

Now it’s permanent.

git commit Flow

Staging Area
     ↓
  Tree Created
     ↓
 Commit Created
     ↓
 HEAD Moves Forward

How Git Tracks Changes (Not File Differences)

Here’s a mind-blowing fact:→Git does NOT track changes line by line.

Git tracks snapshots.

Chai Analogy

Git doesn’t say:→ “Added 1 spoon sugar”

Git says:→ “This is the complete chai recipe now”

Each commit is a full snapshot of the project.

Hashes: Git’s Taste Guarantee

Every Git object is identified by a hash (SHA-1 / SHA-256).

Example:

a1b2c3d4e5f6...

This hash depends on:

  • Content

  • Metadata

Chai Analogy

Think of a hash as:→ A unique taste fingerprint of chai

If someone changes:

  • Sugar amount

  • Ginger quantity

The taste changes — and so does the hash.

Why Hashes Matter

Hashes ensure:

  • No data corruption

  • No silent changes

  • Complete integrity

If history is altered, Git immediately knows.

The Mental Model (This Is the Key)

Instead of memorizing commands, remember this story:

☕ You experiment with chai
☕ You approve good versions
☕ You store recipes permanently
☕ You can revisit any recipe anytime

Git is:→ A content-addressed, immutable recipe book

Once written, history is never rewritten accidentally.