Git is the most widely used version control system in the world. But have you ever wondered what happens under the hood when you run git commit or git push? In this blog, I'll take you through the internals of Git, explaining how it works on your local system and breaking down each component and its responsibility.


What is Git?

Git is a distributed version control system (DVCS) created by Linus Torvalds in 2005 for Linux kernel development. Unlike centralized version control systems, Git gives every developer a full copy of the entire repository history on their local machine.

Key characteristics of Git:


The .git Directory: Where the Magic Happens

When you run git init, Git creates a hidden .git directory in your project root. This directory is the heart of Git — it contains everything Git needs to manage your repository.

.git/
├── HEAD
├── config
├── description
├── hooks/
├── index
├── info/
├── objects/
├── refs/
└── logs/

Let's explore each component in detail.


Git's Core Components

1. Objects Directory (objects/)

The objects/ directory is Git's database. It stores all the content of your repository as objects. Git uses a content-addressable filesystem, meaning objects are stored and retrieved by their SHA-1 hash.

There are four types of objects:

a) Blob (Binary Large Object)