Understanding the Inner Workings of Git

When you run git init command a hidden folder appears named .git. Mostly beginner developers treate this folder like an empty box and they think they should never touch this. But they don't know about the magic your entire project history is being managed in that single folder.
The .git Folder: The Brain of Your Project
Everything Git knows about your project is stored inside the .git directory it's not just a simple folder, your complete project history is being tracked and saved inside it. If you delete this file then Git lose the context means it will no longer recognize it as a git repo.
objects/: This is the most important part. It’s the "database" where all of your file content and history are stored.
refs/: This stores pointers to your commits (like where main or head is currently pointing).
index: This area is known as Staging Area. It’s a binary file used to track the messages that go into the commit.

The Three Git Objects: Blobs, Trees, and Commits
Git stores everything using three main types of objects. To keep things simple, think of them as Files, Folders, and Snapshots.
The Blob (The File Content)
Blob stands for Binary Large Object. Whenever you add a file to Git it doesn't care about the name of that file. It only cares about the content of that file then compresses that content and give it a unique ID. It generates a unique 40-character SHA-1 hash, known as an Object ID (OID). You can consider a Blob like a piece of paper but the paper doesn't have a name yet.
The Tree (The Folder Structure)
A Tree acts like a directory which map the Blob (file content) to their actual filenames. A Tree is like an envelope that says this piece of paper is called style.css.
Commits
A commit is like taking a shanpshot of your project at a specific point at a time. It points to a specific Tree and includes information of all the changes such as who made the change, when they made the change and why. It creates a chain of commit by rendering the history of commits.
How Git Tracks Changes
Git uses a math formula called SHA-1 to create a unique 40 character "Fingerprint" for every object. Enen though if you change a single line of code in your project the Fingerprint(Hash) changes completely.

The Internal Flow: Add and Commit
Let’s look what actually happens "backstage" when you run your two favorite commands:
When you run
git add <filename>
Git looks at your file.
It creates a Blob object for that content.
It updates the index file to say: "Hey, this Blob is ready to be committed."
When you run
git commit
Git creates a Tree object to represent the structure of your project.
It creates a Commit object that points to that Tree.
It moves the HEAD pointer to this new commit.

Git is often treated like a series of magical commands including (push, pull, and commit). It is not as much complicated you just have to these basic commands to move forward.




