Skip to main content

Command Palette

Search for a command to run...

Inside Git : How It Works and the Role of the .git Folder

Updated
Inside Git : How It Works and the Role of the .git Folder
M

I believe writing makes learning easier so I share simple Tech notes with diagrams

Introduction -

Most beginners use Git commands like git add and git commit , but they don’t know what Git is doing inside the folder. Git actually keeps all the tracking information inside a hidden folder called .git this folder is the brain of your Git project. In this blog I will explain how Git will works internally and why the .git folder is important.

How Git Works Internally -

Git is a version control system that stores your project history and does not store “changes only” like a normal backup tool it aslo stores snapshots of your project using objects. Git is like a small database inside your project were everything is stored using hashes (unique IDs).

Understanding the .git Folder -

The .git folder is the “brain” of Git inside your project. When you run git init , Git creates the .git folder and this folder contains complete history of commits we have done , staging area information , branches/tags and configuration.

If you delete the .git folder , The project files remain , but Git history + commits + branches are gone and folder is no longer a Git repo

Important parts inside .git :

  • .git/objects/ - To store all Git objects (blob, tree, commit)

  • .git/refs/ - To store pointers/references to branches and tags

  • .git/HEAD - To show which branch/commit you are currently on

  • .git/index - To store staged changes (files added using git add)

  • .git/config - To store repository settings (remote URL, user config, etc.)

  • .git/logs/ - To keep logs/history of reference updates (branch/HEAD movements)

Git Objects -

Blob object :

Blob is equal to file content as it does not store file name and if two files have same content, Git can reuse the same blob.

Tree object :

Tree is equal to folder structure which stores file names and connects them to blobs. Tree object can also point to other trees (sub-folders).

Commit object :

Commit is equal to snapshot record which points to one top-level tree and it stores metadata:

  • author name/email

  • date/time

  • commit message

  • parent commit (previous commit)

Relationship between commit, tree, blob :

Commit points to a Tree and Tree points to Blobs (files) and other Trees (folders)
Simple flow: Commit → Tree → Blob

How Git Tracks Changes -

Git watches your files and compares changes using internal data.
It stores project history using commits. This is why Git is very fast and reliable. Even if you work offline , Git can still track all changes properly because everything is stored locally in .git

Conclusion -

The .git folder is the most important part of any Git repository. It stores all tracking information like commits, branches, and history. Even if you don’t open or edit the .git folder manually, it is helpful to know that Git uses it to manage your project safely. Understanding this makes Git feel less confusing and more logical for beginners.