<?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://sagarsangle-git-for-beginners-basics.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Wed, 14 Oct 2026 03:01:34 GMT</lastBuildDate><atom:link href="https://sagarsangle-git-for-beginners-basics.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[Once you understand Git’s internal model, the commands stop feeling magical and start feeling obvious.
The Big Picture: What Git Really Is
At its core, Git is a content-addressable database.
That sounds fancy, but here’s the human version:

Git doesn...]]></description><link>https://sagarsangle-git-for-beginners-basics.hashnode.dev/inside-git-how-it-works-and-the-role-of-the-git-folder</link><guid isPermaLink="true">https://sagarsangle-git-for-beginners-basics.hashnode.dev/inside-git-how-it-works-and-the-role-of-the-git-folder</guid><category><![CDATA[Git]]></category><category><![CDATA[WebDevCohort2026]]></category><category><![CDATA[Chaiaurcode]]></category><dc:creator><![CDATA[Sagar Sangle]]></dc:creator><pubDate>Sat, 17 Jan 2026 14:27:42 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1768659756258/e060b754-eefd-4a82-a978-6a58820eace0.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Once you understand Git’s internal model, the commands stop feeling magical and start feeling obvious.</p>
<h2 id="heading-the-big-picture-what-git-really-is">The Big Picture: What Git Really Is</h2>
<p>At its core, Git is a <strong>content-addressable database</strong>.</p>
<p>That sounds fancy, but here’s the human version:</p>
<ul>
<li><p>Git doesn’t track files.</p>
</li>
<li><p>Git tracks <strong>snapshots of content</strong>, and it names those snapshots using cryptographic hashes.</p>
</li>
</ul>
<h2 id="heading-understanding-the-git-folder-why-it-exists">Understanding the <code>.git</code> Folder (Why It Exists)</h2>
<p>When you run <code>git init</code>, Git creates a hidden directory. This folder <strong>is</strong> the repository. Your working directory is just a checkout of what’s stored inside <code>.git</code>.</p>
<p>If you delete <code>.git</code>, your project becomes a normal folder again.</p>
<h3 id="heading-whats-inside">What’s Inside?</h3>
<p>Conceptually, the important parts are:</p>
<div class="hn-table">
<table>
<thead>
<tr>
<td><strong>Path</strong></td><td><strong>Purpose</strong></td></tr>
</thead>
<tbody>
<tr>
<td><code>.git/objects/</code></td><td><strong>The Database.</strong> Stores all Git data (files, folders, commits).</td></tr>
<tr>
<td><code>.git/refs/</code></td><td>Stores pointers for branches and tags.</td></tr>
<tr>
<td><code>.git/HEAD</code></td><td>A text file telling Git what branch you’re currently on.</td></tr>
<tr>
<td><code>.git/index</code></td><td>The <strong>Staging Area</strong>. A binary file tracking what will go into the next commit.</td></tr>
</tbody>
</table>
</div><h2 id="heading-git-objects">Git Objects:</h2>
<p>Git only knows three object types. Once you understand these, Git clicks.</p>
<h3 id="heading-1-blob-here-is-some-content">1. Blob — “Here is some content”</h3>
<p>A blob (Binary Large Object) is the contents of a file.</p>
<ul>
<li><p>Nothing else.</p>
</li>
<li><p>No filename.</p>
</li>
<li><p>No permissions.</p>
</li>
<li><p>Just raw bytes.</p>
<p>  <strong>Note:</strong> If two files have the exact same content even with different names—Git stores only <strong>one</strong> blob.</p>
</li>
</ul>
<h3 id="heading-2-tree-heres-a-folder-structure">2. Tree — “Here’s a folder structure”</h3>
<p>A tree maps filenames to blobs or other trees. It represents a directory.</p>
<h3 id="heading-3-commit-heres-a-snapshot-context">3. Commit — “Here’s a snapshot + context”</h3>
<p>A commit contains:</p>
<ul>
<li><p>A reference to one <strong>root tree</strong>.</p>
</li>
<li><p>Author &amp; timestamp.</p>
</li>
<li><p>Commit message.</p>
</li>
<li><p>Parent commit(s).</p>
</li>
</ul>
<p>A commit does not store file contents directly. It just points to a tree, which points to blobs.</p>
<h3 id="heading-visualizing-the-relationship">Visualizing the Relationship</h3>
<p>Here is the entire Git data model in one view:</p>
<pre><code class="lang-plaintext">[ COMMIT e7d13b ]
      |
      +-- points to --&gt; [ TREE (Root) ]
                             |
                             +-- "README.md" --&gt; [ BLOB (content) ]
                             |
                             +-- "src/" -------&gt; [ TREE (Folder) ]
                                                      |
                                                      +-- "app.js" --&gt; [ BLOB (content) ]
</code></pre>
<h2 id="heading-how-git-tracks-changes">How Git Tracks Changes</h2>
<p>Git does not store diffs internally.</p>
<p>Instead, <strong>every commit is a complete snapshot.</strong></p>
<ul>
<li><p>If a file hasn't changed, the new tree simply points to the <strong>existing blob</strong>.</p>
</li>
<li><p>If a file has changed, the new tree points to a <strong>new blob</strong>.</p>
</li>
</ul>
<p>So Git <em>feels</em> like it tracks changes—but internally it just links snapshots efficiently.</p>
<h2 id="heading-what-really-happens-during-git-add">What Really Happens During <code>git add</code></h2>
<p>Let’s say you modify a file named <code>hello.txt</code>.</p>
<p><strong>Step-by-Step Internally:</strong></p>
<ol>
<li><p>Git reads the file contents.</p>
</li>
<li><p>Git hashes the contents (SHA-1).</p>
</li>
<li><p>Git stores the content as a <strong>blob</strong> in <code>.git/objects</code>.</p>
</li>
<li><p>Git updates the <strong>index</strong> (staging area) to point to that blob.</p>
</li>
</ol>
<h2 id="heading-what-really-happens-during-git-commit">What Really Happens During <code>git commit</code></h2>
<p>Now Git creates history.</p>
<p><strong>Internally, Git:</strong></p>
<ol>
<li><p>Reads the staging area.</p>
</li>
<li><p>Builds <strong>tree objects</strong> from staged blobs.</p>
</li>
<li><p>Creates a <strong>commit object</strong> pointing to the root tree.</p>
</li>
<li><p>Stores the commit in <code>.git/objects</code>.</p>
</li>
<li><p>Moves the current branch pointer to the new commit.</p>
</li>
</ol>
<p><strong>That’s it.</strong> No files copied. No diffs saved. Just new objects and new pointers.</p>
<h3 id="heading-the-workflow-diagram">The Workflow Diagram</h3>
<pre><code class="lang-plaintext">   WORKING DIR          STAGING AREA           .GIT REPO
 (Files on disk)          (Index)             (Database)
      |                      |                     |
      | -- git add  -------&gt; |                     |
      |                      | -- git commit ----&gt; |
      |                      |                     |
[Modified File]      [Pointer to Blob]    [Commit -&gt; Tree -&gt; Blob]
</code></pre>
<h2 id="heading-how-git-uses-hashes-why-integrity-is-guaranteed">How Git Uses Hashes (Why Integrity Is Guaranteed)</h2>
<p>Every Git object is named by a hash (e.g., <code>e7d13b0f7c2d...</code>). That hash is computed from the <strong>Object Type + Object Content</strong>.</p>
<p><strong>Why This Matters:</strong></p>
<ul>
<li><p>If content changes → hash changes.</p>
</li>
<li><p>If a hash changes → every parent hash breaks.</p>
</li>
</ul>
<p>This makes history tamper-evident. Git doesn’t ask “What changed?” Git asks “Do I already have this exact content?”</p>
<h2 id="heading-the-mental-model">The Mental Model</h2>
<p>If you remember only this:</p>
<p><strong>Git is a graph of snapshots, not a list of changes.</strong></p>
<p>Then the commands become descriptions of intent, not magic spells:</p>
<ul>
<li><p>git add = Stage content snapshots.</p>
</li>
<li><p>git commit = Lock in a snapshot with metadata.</p>
</li>
<li><p>Branches = Movable pointers.</p>
</li>
<li><p>HEAD = Where you are right now.</p>
</li>
</ul>
]]></content:encoded></item></channel></rss>