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

Published: (January 3, 2026 at 11:48 AM EST)
3 min read
Source: Dev.to

Source: Dev.to

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

Most developers use Git every day with commands like git init, git add, and git commit, but only a few know how Git actually handles these commits internally.

In this blog we’ll look inside Git, see how it works internally, and explore the important role of the .git folder.

What is Git? (Quick Recap)

Git is a version‑control system that helps developers track changes, collaborate, and manage project history efficiently.

If you want to learn more about Git, you can read this blog too. 👇

How Git Works (Internal View)

Git works in three main areas:

  1. Working Directory – Your actual project files.
  2. Staging Area – Where changes are prepared.
  3. Repository – Where Git permanently stores snapshots.

Every time you commit, Git:

  • Takes a snapshot of all tracked files.
  • Stores it safely inside the .git directory.
  • Links commits together.

Git internal diagram

The Heart of Git: The .git Folder

When you run:

git init

Git creates a hidden folder inside your project root. It’s there—you just can’t see it in the file explorer.

👉 This folder is the entire brain of Git.
If it’s deleted, your project is no longer a Git repository.

What’s Inside the .git Folder?

You can also view it from the command line:

cd .git
ls -la

objects/ – Where Everything Is Stored

This directory holds all Git data: commits, files, and directory structures.

Objects directory

  • Commit objects – snapshots of the repository at a point in time.
  • Tree objects – represent directory hierarchies.
  • Blob objects – store file contents.

Note: git log shows only commit objects, while .git/objects also contains trees and blobs, which is why you’ll see more directories than commits.

refs/ – Branch & Tag Pointers

This folder keeps references to branches and tags.

Refs directory

  • Branches (refs/heads) – point to the latest commit of each branch.
  • Tags (refs/tags) – mark specific commits.

Each branch is simply a pointer to a commit hash.

Branch pointer example

HEAD – Where You Are Right Now

The HEAD file tells Git:

  • Which branch you are on.
  • Which commit is currently checked out.

HEAD file

index – The Staging Area

The index (or staging area) stores:

  • Files you added with git add.
  • The exact snapshot that will become the next commit.

It acts as a bridge between the working directory and the repository.

config – Repository Settings

The config file contains:

  • Remote URLs.
  • User configurations (name, email).
  • Repository‑specific settings.

Config file

TL;DR

  • Git stores everything in the hidden .git directory.
  • objects/ holds the raw data (commits, trees, blobs).
  • refs/ tracks branches and tags.
  • HEAD points to the current branch/commit.
  • index is the staging area.
  • config holds repository configuration.

Understanding these components demystifies how Git tracks changes and why operations like git commit, git checkout, and git push work the way they do. Happy committing! 🚀

The Basic Workflow

# Initialize a git repository
git init

# Stage changes
git add .

# Commit the staged changes
git commit -m "message"

What Git Does

  • Initializing the repository creates the .git directory.
  • git add stores the staged files as blob objects in .git/objects/.
  • git commit -m "message" builds a tree object that represents the directory structure.
  • Git then creates a commit object containing:
    • A pointer to the root tree.
    • A pointer to the parent commit (if any).
    • Author and committer information.
    • A timestamp.
    • The commit message.

git commit object diagram

Image credit: Photo by freeCodeCamp

Final Thoughts

Git may look simple on the surface, but internally it’s a powerful database.
The .git folder is not just a config folder; it contains the entire history and structure of your project.

Thanks for reading! If you enjoyed this post, you can read more on the topics below:

Author profile image

Back to Blog

Related posts

Read more »

Commit Message Format

Commit Message Format Each commit message consists of a header, a body, and a footer. The header has a special format that includes a type, an optional scope,...

Git for Beginners

What is Git? Git is a tool that helps you save, track, and manage changes in your code. In simple words: Git remembers every version of your project so you can...

Git Learning

What is Git Git was created by Linus Torvalds in 2005. Version Control Systems Types of Version Control Systems 1. Local VCS - Example: none provided - Limitat...