Skip to main content

Command Palette

Search for a command to run...

Git Essentials: What Happens Inside the .git Folder

Published
2 min read

When I first saw git it felt like magic, file change, commit appear and history preserved. But behind the scenes git follows a very simple and powerful model. Let's understand that in this article.

How Git Works Internally?

In simple terms, git is a content tracking system, not just a file tracker.

  • It takes snapshots of our Project.

  • Stores them efficiently.

links them together using cryptographic hashes.

Understanding The .git Folder

This is the brain of our Repository. If we delete this folder then git history is gone.

The inside .git folder

  • objects/ : Where get stores all data (files, folder, commits)

  • refs/ : Pointers to branches and tags

  • HEAD : Tells git which branch you are on.

  • Index : The staging area

Git Objects: Blob, Tree, Commit

git stores everything as objects.

  1. Blob (file content)

    • Stores the content of the file.

    • No file name no path just raw data.

    • Same content = same blob (across even across files)

  2. Tree (folder structure)

    • Represents the directory

    • Maps filenames to blobs

    • Defines how files are arranged

  3. Commit (snapshot)

    • Points to one tree (the project state)

    • Stores metadata (author, message, time)

    • Points to the previous commit

How Git Tracks Changes

Git doesn’t store changes line by line. It stores new objects only when content changes.

Example:

  • You edit one file

  • Git creates a new blob for that file

  • Other unchanged files reuse old blobs

  • A new tree and commit are created

This is why Git is:

  • Fast

  • Reliable

What Happens During git add and git commit

git add

  • Read file’s content

  • Create blob objects

  • Updates the index

git commit

  • Reads the staging area

  • Creates a tree object

  • Creates a commit object

  • Moves the branch pointer forward

How Git uses Hashes for Integrity

Every git object is identified by a Hash. It depends on object content and object type.

It means:

  • when the content is changed the hash changes

  • Tampering is instantly detectable

  • History cannot be silently modified

This is how git ensures Integrity.

Closing Statement

Git feels like magic but knowing its internal makes you trust it confidently. When you know what's happening inside git folder it becomes Predictable and Powerful.