No history yet

Git Architecture and Snapshots

Thinking in Snapshots

Most version control systems think in terms of differences. When you save a new version of a file, they store the specific lines you added or removed. This is often called delta-based tracking. If you want to see the current version, the system starts with the original file and applies every single change in order.

Git doesn't do this. It thinks in snapshots. When you save your work, Git essentially takes a picture of what all your files look like at that moment and stores a reference to that snapshot. If files haven't changed from one version to the next, Git doesn't store the file again. It just includes a link to the previous, identical file it has already stored.

This makes operations like checking out a previous version or comparing branches incredibly fast, because Git doesn't have to reconstruct the state of your project. It just grabs the complete snapshot.

Creating a Repository

To start tracking a project with Git, you first need to initialise a repository. This is a one-time command you run inside your project's main folder. It tells Git to start watching this folder for changes.

# Navigate to your project directory
cd my-project

# Initialise a Git repository
git init

When you run git init, Git creates a hidden subdirectory named .git. This directory is the heart of your repository. It contains all the snapshots, historical information, and configuration that Git needs to perform its work. You almost never need to touch the files inside it directly, but understanding its structure is key to mastering Git.

Inside the .git Directory

The .git directory is where Git stores its entire database and metadata. While it contains several files and folders, the most important one for now is the objects directory. This is Git's object database, where it stores all your content.

Every time you commit, Git creates objects representing your project's state. There are a few types of objects, but the most central is the commit object. A commit object is a snapshot of your entire project at a specific point in time. It contains metadata like the author, a commit message, and, crucially, a pointer to the parent commit(s) that came before it.

Each object in the database is identified by a unique 40-character checksum hash. This is generated using a hashing algorithm called SHA-1. This hash is computed based on the contents of the object itself. This means that if you change even a single character in a file, the resulting hash will be completely different, ensuring the integrity of your data.

This series of commits, each pointing to its parent, forms a history. This structure is known as a directed acyclic graph (DAG), which is just a fancy way of saying that commits have a clear, one-way chronological order and you can't have a circular history.

Now, let's test your understanding of these core concepts.

Quiz Questions 1/4

How does Git's approach to storing versions primarily differ from many other version control systems that use delta-based tracking?

Quiz Questions 2/4

When you run the git init command in a directory, what is the main purpose of the hidden .git folder that is created?

Understanding this snapshot-based architecture is the foundation for everything else you'll do in Git, from branching to merging.