Skip to main content

Command Palette

Search for a command to run...

How Git Works Internally

Updated
3 min read
How Git Works Internally

In this article we will dive into how actually Git works and how it magically remembers all the versions of our code files. Well before moving on we need to know one simple idea that “Git is a memory box of your project”. It remembers each and every version of your code. so you can:

  • go back in time

  • track what changed

  • and work safely without fear

Everything git knows lives in one place.


What is the .git folder

When you run:

git init

Git creates a hidden folder called .git

You can think of .git folder as Git’s brain.

  • Your files = body

  • .git folder = brain

  • No brain → no memory → no Git

So if you delete .git folder

❌ No history
❌ No commits
❌ No branches

It just becomes a normal folder again. That is how powerful .git folder is.

What does Git store in its brain?

Git stores snapshots.

📸 A snapshot =

“How all files looked at one moment”

Not instructions.
Not diffs.
Pictures of your project.


Git’s building blocks

Git uses only 3 main blocks:

1️⃣ File content (Blob)

  • The text inside a file

  • Git doesn’t care about file names here


2️⃣ Folder list (Tree)

  • Knows:

    • file names

    • which content belongs to which file


3️⃣ Snapshot (Commit)

A commit says:

  • Which files existed

  • What was inside them

  • A message like: “Add login feature”

What REALLY happens during git add

You run:

git add file.js

Git does this:

  1. Reads the file content

  2. Saves it safely in .git

  3. Adds it to the staging checklist

That’s it.

git add does NOT save history
❗ It only prepares

What REALLY happens during git commit

Now Git takes the photo 📸

When you run:

git commit -m "message"

Git:

  1. Looks at the staging checklist

  2. Takes a snapshot

  3. Stores it forever

  4. Moves the timeline forward

🎉 That snapshot is your commit.

🔐 What are Git hashes? (No math, promise)

Git gives everything a unique ID.

Like:

  • Aadhaar number

  • Fingerprint 🖐️

If the content changes:
➡️ the ID changes

This means:

  • No fake history

  • No silent changes

  • 100% trust

Git — Simple Summary

  • Git is a memory system for your code. It remembers every version of your project.

  • The .git folder is Git’s brain. All history, commits, and branches live there.

  • Git saves snapshots, not just changes.

  • Your files live in the working directory.

  • The staging area is a checklist of what will go into the next snapshot.

  • git add = choose files for the snapshot.

  • git commit = take the snapshot and save it forever.

  • Git uses hashes (unique IDs) to make sure nothing is changed or corrupted.
    -- Mental model: edit → select → snapshot → remember forever.

Understanding Git's Internal Mechanics