---
title: "Inside Git: How it works and the role of .git folder | Rahul Jha"
description: "Git is one of the most widely used tools in software development. Many developers learn git by memorizing the commands without truly understanding what…"
url: https://rahuljha.info/blog/inside-git-how-it-works-and-the-role-of-git-folder/
---

1.  [Home](https://rahuljha.info/)
2.  [Blog](https://rahuljha.info/blog/)
3.  Inside Git: How it works and the role of .git folder

# Inside Git: How it works and the role of .git folder

By [Rahul Jha](https://rahuljha.info/about/)26 January 20262 min read

Git is one of the most widely used tools in software development. Many developers learn git by memorizing the commands without truly understanding what git is doing behind the scenes.

This article explains how git works internally. We will focus on the .git folder, git objects, and how git keep tracks of our changes.

## How Git Works Internally (The Big Picture)

At its core, **Git** is not just a set of commands - it is a **database** for our project.

Instead of storing “changes between files,” Git stores:

-   Snapshots of project state
    
-   Indexed by hashes
    
-   Connected through objects
    

Every commit, branch, and tag is simply a reference to objects inside the `.git` directory.

> If you understand the `.git` folder, you understand Git.

## Understanding the `.git` Folder

The `.git` directory is the **entire Git repository**. Your working directory is just files. `.git` is where Git stores everything it knows about the project.

If the `.git` folder is deleted, the project instantly loses all version control history.

### Key Responsibilities of `.git`

-   Store all versions of tracked files
    
-   Maintain commit history
    
-   Track branches and tags
    

### Simplified `.git` Directory Structure

```
.git/
├── objects/     # All Git objects (data store)
├── refs/        # Branch and tag pointers
├── HEAD         # Pointer to current branch
├── index        # Staging area
├── config       # Repository configuration
```

### Commit — A Snapshot in Time

A **commit** ties everything together.

A commit contains:

-   A reference to a **tree** (project snapshot)
    
-   Author and timestamp
    
-   Commit message
    
-   Reference to **parent commit(s)**
    

> A commit is **not a diff**.  
> It is a complete snapshot of the project state.

## How Git Tracks Changes

Git does **not** track changes line-by-line like traditional version control systems.

Instead:

1.  Git stores **snapshots**
    
2.  Unchanged files reuse existing blobs
    
3.  Only new content creates new objects
    

* * *

## What Happens Internally During `git add`

![https://phoenixnap.com/kb/wp-content/uploads/2021/09/git-workflow.png](https://phoenixnap.com/kb/wp-content/uploads/2021/09/git-workflow.png)

![https://miro.medium.com/1%2AdiRLm1S5hkVoh5qeArND0Q.png](https://miro.medium.com/1%2AdiRLm1S5hkVoh5qeArND0Q.png)

When you run:

```
git add index.html
```

Internally:

1.  Git reads `index.html`
    
2.  Creates a **file** from its content
    
3.  Stores the file in `.git/objects`
    
4.  Updates the **index (staging area)**:
    

### Key Insight

`git add` does **not** create a commit.  
It updates the **staging snapshot**.

* * *

## What Happens Internally During `git commit`

![https://git-scm.com/book/en/v2/images/data-model-3.png](https://git-scm.com/book/en/v2/images/data-model-3.png)

When you run:

```
git commit -m "Initial commit"
```

Internally:

1.  Git reads the **index**
    
2.  Builds a **tree** representing the directory structure
    
3.  Creates a **commit** pointing to that tree
    
4.  Updates the current branch pointer
    
5.  Moves `HEAD` to the new commit
    

## Why This Understanding Matters

When you understand Git internally:

-   Merge conflicts become logical
    
-   Rebasing stops feeling dangerous
    
-   Detached HEAD is no longer confusing
    
-   Git errors become debuggable, not scary
    

You stop memorizing commands—and start **reasoning about state**.

Topics

-   ChaiCode

Working on a product?

I take on audits, product builds, fractional and contract engagements, and senior roles.

[Start a conversation](https://rahuljha.info/contact/)

## Keep reading

-   [5 Jan 2026
    
    ### Git for Beginners: Basics and Essential Commands
    
    Learn Git from scratch with this beginner-friendly guide. Understand Git basics, essential commands, workflow, and best practices to get started with…
    
    2 min read · version control, Git, Programming Tips](https://rahuljha.info/blog/git-for-beginners-basics-and-essential-commands/)
-   [30 Dec 2023
    
    ### How much JavaScript is required to get started with ReactJS?
    
    ReactJS is a popular JavaScript library used for building user interfaces. While it greatly simplifies the process of creating interactive web…
    
    5 min read · JavaScript, React, javascript framework](https://rahuljha.info/blog/how-much-javascript-is-required-to-get-started-with-reactjs/)

## Have something worth building?

Tell me about the product, the timeline and what success looks like, or send the role you are hiring for. Every engagement begins with a conversation, not a sales call.

[Start a conversation](https://rahuljha.info/contact/)[hello@rahuljha.info](mailto:hello@rahuljha.info)
