Almost every software engineer uses Git every single day:
git add .
git commit -m "fix bug"
git push origin main
Yet to many developers, Git feels like a mysterious black box. When an ugly merge conflict or detached HEAD state occurs, panic sets in, and people resort to deleting the folder and re-cloning the repository.
Git is not an opaque mystery. At its core, Git is a remarkably simple, elegant content-addressable key-value object database paired with a Directed Acyclic Graph (DAG).
In this deep dive, we explore what actually lives inside the .git directory and master how Git resolves conflicts.
The 4 Core Object Types in .git/objects
Every file, folder, and commit in Git is stored as an immutable object compressed with zlib. The filename is the SHA-1 (or SHA-256) hash of its content.
+-----------------------------+
| Commit Object |
| - Author / Timestamp |
| - Parent: a1b2c3d |
| - Tree: 7f8e9a0 (Root Dir) |
+-----------------------------+
|
v
+-----------------------------+
| Tree Object (Directory) |
| - 100644 blob e69de29 main.py
| - 040000 tree 4b825dc src/ |
+-----------------------------+
|
v
+-----------------------------+
| Blob Object (File Content) |
| "print('Hello, Git!')" |
+-----------------------------+
- Blob: Stores raw file content. (No filename or permissions).
- Tree: Represents a directory with filenames and mode permissions.
- Commit: Contains commit message, author info, timestamp, pointer to root Tree, and Parent Commits.
Resolving Ugly Merge Conflicts with git rerere
One of Git's best-kept secrets is rerere (Reuse Recorded Resolution).
If you rebase long-lived feature branches, you often have to resolve the exact same merge conflict multiple times.
Enable rerere globally:
git config --global rerere.enabled true
How it Works:
- When a merge conflict occurs, Git records a snapshot of the conflict.
- When you manually resolve it and commit, Git records the resolution.
- In future rebases or merges, whenever the exact same conflict occurs anywhere in the repository, Git automatically resolves it for you!

Top comments (0)