# Git Under the Hood: A Look Inside the .git Folder & Architecture

Confession Time: For the longest time, I used Git blindly. I would just memorize commands like `git add` and `git commit` , cross my finger, and hope no error (red lines) appears on console without actually understanding what was happening behind the scenes.

If you have ever run `ls -a` in your project terminal, you have probably seen a hidden folder named `.git` . Most of us ignore it (including me). But in reality, that folder isn’t just random folder - it is the brain, heart, and soul of your entire project.

To really understand Git, we need to look inside the .git folder.

## The `.git` Folder

The moment we type `git init` in our terminal, Git creates a hidden folder.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1768579715067/5a144d2e-b719-4fd5-8432-93c951a29b70.png align="center")

Earlier when people used to say “Git track changes” I used to think that its watching me type in the real-time. No instead it’s wait for you to tell to take a snapshot (like a screenshot of your code at that particular time). All those snapshots, all the history, and all the code versions are stored right inside this `.git` folder.

And also if you delete this folder `rm -rf .git`, your project becomes just a regular folder again. You lose every commit, every branch, and every piece of history.

### `.git` Directory Structure

```plaintext
.git/
|--config            # repository-specific settings & configurations
|--description       # repo info for tools 
|--HEAD              # tells current branch
|--hooks/            # event automation scripts 
|--info/             # local ignore rules
|--objects/          # git core data storage 
|--refs/             # branch and tag pointers
```

## How Git “Thinks” : The Objects

Inside `.git`, Git stores everything as objects. When we look inside `.git/objects`, you will see bunch of subfolders named with two random characters.

These are not random. Git compresses your data and stores it. There are three main types of objects:

1. Blobs (Binary Large Objects): This is the raw content of your files. If you have a file named `sample.js`, Git converts its text into a “blob”. It does not store file name, nor any folder structure just store raw data.
    
2. Trees: Think of a tree as a directory listing. It maps filenames to their Blobs. It captures the structure of your folder.
    
3. Commits: A commit objects contains reference to a tree, Author name, Message, and most important the previos commit hash.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1768586492644/b0fc56ec-4fe6-41dc-94b1-27364f3f1089.png align="center")

## The Internal Workflow: From `add` to `commit`

Let’s follow the real internal flow

**Step 1** - You edit a File (sample.js)

we have modified this file, Git knows it’s changed but it isn’t tracking it yet.

**Step 2** - `git add sample.js`

When you run `git add <filename>`, you are moving the sample.js to the Staging Area and creates a blob object. This area is like “Ready to be committed”.

**Step 3** - `git commit -m “message”`

When you run this command, Git takes everything currently in the Staging Area and permanently stores it in the `.git` folder. It creates a new Commit Object with a unique ID (Hash).

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1768588620536/8eaceb03-6a19-456f-a9e6-59c26845f43f.png align="center")

## How Git Tracks Changes with Hashes

Git does not uses version numbers like v1, v2 or final, final\_final like we college students do with our projects. It uses something called SHA-1 hashes.

Every time we commits, git generates a uniques ID (like 3a7f9c2d...) based on the content. If you change even a single space in your code, the hash changes completely. This ensures Integrity - no one can secretly alter the code history without breaking the chain.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1768589656638/93fd79bb-9a88-4d27-8167-fb915213023e.png align="center")

## \# Final Thoughts

Git works internally though:

* Blobs → file content
    
* Trees → structure
    
* Commits → snapshots
    
* Hashes → identity
    
* `.git` → complete database
    

Understanding this makes you confident because:

> You are no longer memorizing Git - you are understanding Git.
