<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Inside Git: How It Works]]></title><description><![CDATA[Inside Git: How It Works]]></description><link>https://inside-git-working-role.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Wed, 14 Oct 2026 12:15:07 GMT</lastBuildDate><atom:link href="https://inside-git-working-role.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Inside Git: How It Works and the Role of the .git Folder]]></title><description><![CDATA[How Git Works Internally: Building a Mental Model
Most beginners learn Git by memorizing commands, but Git becomes truly powerful when you understand how it works internally. This blog explains Git’s internals in a simple, conceptual, and beginner-fr...]]></description><link>https://inside-git-working-role.hashnode.dev/inside-git-how-it-works-and-the-role-of-the-git-folder</link><guid isPermaLink="true">https://inside-git-working-role.hashnode.dev/inside-git-how-it-works-and-the-role-of-the-git-folder</guid><category><![CDATA[working of git]]></category><category><![CDATA[structuregit]]></category><category><![CDATA[Git]]></category><category><![CDATA[insidegit]]></category><dc:creator><![CDATA[Pranay Islary]]></dc:creator><pubDate>Fri, 16 Jan 2026 13:05:04 GMT</pubDate><content:encoded><![CDATA[<h1 id="heading-how-git-works-internally-building-a-mental-model">How Git Works Internally: Building a Mental Model</h1>
<p>Most beginners learn Git by memorizing commands, but Git becomes truly powerful when you understand <strong>how it works internally</strong>. This blog explains Git’s internals in a <strong>simple, conceptual, and beginner-friendly way</strong>, so you can reason about Git instead of guessing.</p>
<h2 id="heading-why-understand-git-internals">Why Understand Git Internals?</h2>
<p>Understanding Git internally helps you:</p>
<ul>
<li><p>Debug issues confidently</p>
</li>
<li><p>Recover lost work</p>
</li>
<li><p>Understand <em>why</em> Git behaves the way it does</p>
</li>
<li><p>Stop memorizing commands and start reasoning logically</p>
</li>
</ul>
<p>Git is not magic—it’s a <strong>content-addressable file system</strong> with a smart history tracker.</p>
<h2 id="heading-the-git-folder-the-heart-of-git">The <code>.git</code> Folder: The Heart of Git</h2>
<p>When you run:</p>
<pre><code class="lang-bash">git init
</code></pre>
<p>Git creates a hidden folder called <code>.git</code>. This folder contains <strong>everything Git knows about your project</strong>.</p>
<p><strong><em>If you delete the</em></strong> <code>.git</code> <strong><em>folder, your project files remain—but Git history is gone.</em></strong></p>
<h2 id="heading-why-does-the-git-folder-exist">Why Does the <code>.git</code> Folder Exist?</h2>
<p>The <code>.git</code> folder exists to:</p>
<ul>
<li><p>Store the complete history of your project</p>
</li>
<li><p>Track file versions and changes</p>
</li>
<li><p>Manage branches, commits, and tags</p>
</li>
<li><p>Ensure data integrity</p>
</li>
</ul>
<p>Your working directory is just files.<br /><strong>The</strong> <code>.git</code> folder is Git itself.</p>
<h2 id="heading-structure-of-the-git-directory-conceptual-diagram">Structure of the <code>.git</code> Directory (Conceptual Diagram)</h2>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1768567217380/a597a928-ca2f-4572-87a9-717375b8c3af.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-git-objects-the-building-blocks">Git Objects: The Building Blocks</h2>
<p>Git stores everything as <strong>objects</strong>. There are three core Git objects:</p>
<ol>
<li><p><strong>Blob</strong></p>
</li>
<li><p><strong>Tree</strong></p>
</li>
<li><p><strong>Commit</strong></p>
</li>
</ol>
<p>Understanding these three gives you a complete mental model of Git.</p>
<h2 id="heading-1-blob-binary-large-object">1. Blob (Binary Large Object)</h2>
<p>A <strong>blob</strong> stores the <em>content</em> of a file.</p>
<p>Important points:</p>
<ul>
<li><p>Blobs store <strong>file data only</strong>, not filenames</p>
</li>
<li><p>Same content = same blob (even across different files)</p>
</li>
<li><p>If content doesn’t change, Git reuses the blob</p>
<p>  <strong><em>Git tracks content, not files.</em></strong></p>
</li>
</ul>
<h2 id="heading-2-tree">2. Tree</h2>
<p>A <strong>tree</strong> represents a directory.</p>
<p>It contains:</p>
<ul>
<li><p>File names</p>
</li>
<li><p>Folder structure</p>
</li>
<li><p>References to blobs (files) and other trees (subdirectories)</p>
</li>
</ul>
<p>Think of a tree as a <strong>snapshot of your project structure</strong>.</p>
<h2 id="heading-3-commit">3. Commit</h2>
<p>A <strong>commit</strong> is a snapshot of your project at a point in time.</p>
<p>A commit contains:</p>
<ul>
<li><p>A reference to a tree (project snapshot)</p>
</li>
<li><p>Parent commit(s)</p>
</li>
<li><p>Author information</p>
</li>
<li><p>Commit message</p>
</li>
<li><p>Timestamp</p>
</li>
</ul>
<p>Commits form a <strong>linked history</strong>.</p>
<h2 id="heading-relationship-between-git-objects-diagram-idea">Relationship Between Git Objects (Diagram Idea)</h2>
<pre><code class="lang-plaintext">Commit
  ↓
 Tree
  ↓
Blobs (file contents)
</code></pre>
<p>Each commit points to a tree, and each tree points to blobs.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1768567753976/405baf1e-7bce-4431-a089-5d507b3091f1.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-how-git-tracks-changes">How Git Tracks Changes</h2>
<p>Git does <strong>not</strong> store differences like traditional version control systems.</p>
<p>Instead, Git:</p>
<ul>
<li><p>Takes snapshots of your project</p>
</li>
<li><p>Reuses unchanged objects</p>
</li>
<li><p>Creates new objects only for changed content</p>
</li>
</ul>
<p>This makes Git fast and storage-efficient.</p>
<h2 id="heading-what-happens-internally-during-git-add">What Happens Internally During <code>git add</code></h2>
<p>When you run:</p>
<pre><code class="lang-bash">git add file.txt
</code></pre>
<p>Internally, Git:</p>
<ol>
<li><p>Reads the file content</p>
</li>
<li><p>Creates a <strong>blob object</strong> from the content</p>
</li>
<li><p>Generates a <strong>hash</strong> for the blob</p>
</li>
<li><p>Stores it inside <code>.git/objects</code></p>
</li>
<li><p>Updates the <strong>index (staging area)</strong> to point to that blob</p>
<p> <code>git add</code> <strong><em>does NOT create a commit.</em></strong></p>
</li>
</ol>
<h2 id="heading-what-happens-internally-during-git-commit">What Happens Internally During <code>git commit</code></h2>
<p>When you run:</p>
<pre><code class="lang-bash">git commit -m <span class="hljs-string">"message"</span>
</code></pre>
<p>Git performs the following steps:</p>
<ol>
<li><p>Reads the staging area (index)</p>
</li>
<li><p>Creates a <strong>tree object</strong> representing the project structure</p>
</li>
<li><p>Creates a <strong>commit object</strong> pointing to the tree</p>
</li>
<li><p>Updates the current branch reference</p>
</li>
<li><p>Moves <code>HEAD</code> to the new commit</p>
</li>
</ol>
<h2 id="heading-internal-flow-of-git-add-and-git-commit-diagram-idea">Internal Flow of <code>git add</code> and <code>git commit</code> (Diagram Idea)</h2>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1768568260057/796b2399-f264-4389-bad3-3f297485dedb.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-how-git-uses-hashes-sha-1-sha-256">How Git Uses Hashes (SHA-1 / SHA-256)</h2>
<p>Every Git object is identified by a <strong>cryptographic hash</strong>.</p>
<p>This hash is generated from:</p>
<ul>
<li><p>Object type</p>
</li>
<li><p>Object content</p>
</li>
<li><p>Object size</p>
</li>
</ul>
<h3 id="heading-why-hashes-matter">Why Hashes Matter</h3>
<p>Hashes ensure:</p>
<ul>
<li><p><strong>Data integrity</strong> – content cannot be changed unnoticed</p>
</li>
<li><p><strong>Uniqueness</strong> – same content always produces the same hash</p>
</li>
<li><p><strong>Security</strong> – tampering breaks the hash chain</p>
<p>  <strong><em>Git is effectively a tamper-proof history system.</em></strong></p>
</li>
</ul>
<h2 id="heading-hash-based-integrity-chain">Hash-Based Integrity Chain</h2>
<pre><code class="lang-plaintext">Commit Hash
  ↓
Tree Hash
  ↓
Blob Hashes
</code></pre>
<p>If any blob changes, the tree hash changes.<br />If the tree hash changes, the commit hash changes.</p>
<p>This guarantees full history integrity.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1768568551551/465c1076-aba0-412d-8cf5-2846a62ec20a.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-building-the-right-mental-model-of-git">Building the Right Mental Model of Git</h2>
<p>Instead of thinking:</p>
<p><strong><em>“Git is a set of commands”</em></strong></p>
<p>Think:</p>
<p><strong><em>“Git is a database of snapshots linked by hashes”</em></strong></p>
<ul>
<li><p>Files → blobs</p>
</li>
<li><p>Folders → trees</p>
</li>
<li><p>Versions → commits</p>
</li>
<li><p>Branches → pointers</p>
</li>
</ul>
<p>Once this clicks, Git becomes predictable and logical.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Git works internally by storing content as objects and linking them together using cryptographic hashes. The <code>.git</code> folder is not mysterious—it’s simply a well-organized database that records every version of your project.</p>
<p>By understanding blobs, trees, commits, and how <code>git add</code> and <code>git commit</code> work internally, you move from <em>using</em> Git to truly <em>understanding</em> it.</p>
<p><strong><em>When you understand Git’s internals, Git stops being scary and starts being powerful.</em></strong></p>
]]></content:encoded></item></channel></rss>