<?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[Git: How it work and role .git Folder]]></title><description><![CDATA[Git: How it work and role .git Folder]]></description><link>https://git-howitworks.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Mon, 31 Aug 2026 20:20:48 GMT</lastBuildDate><atom:link href="https://git-howitworks.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 Really Works Behind the Scenes
Most people learn Git like this:
✅ git add✅ git commit✅ git push
But many developers still feel confused because they don’t understand what Git actually does inside.
So in this blog, we’ll build a strong ment...]]></description><link>https://git-howitworks.hashnode.dev/inside-git-how-it-works-and-the-role-of-the-git-folder</link><guid isPermaLink="true">https://git-howitworks.hashnode.dev/inside-git-how-it-works-and-the-role-of-the-git-folder</guid><dc:creator><![CDATA[Rahul Verma]]></dc:creator><pubDate>Tue, 13 Jan 2026 03:57:02 GMT</pubDate><content:encoded><![CDATA[<h2 id="heading-how-git-really-works-behind-the-scenes">🧠 How Git Really Works Behind the Scenes</h2>
<p>Most people learn Git like this:</p>
<p>✅ <code>git add</code><br />✅ <code>git commit</code><br />✅ <code>git push</code></p>
<p>But many developers still feel confused because they don’t understand <strong>what Git actually does inside</strong>.</p>
<p>So in this blog, we’ll build a strong mental model of Git internals — in the simplest way possible.</p>
<hr />
<h2 id="heading-what-git-really-is-not-just-commands">✅ What Git Really Is (Not Just Commands)</h2>
<p>Git is basically a <strong>database</strong> that stores your project history.</p>
<p>But it stores data in a very smart way:</p>
<p>✅ It stores <strong>snapshots</strong> (not normal file copies)<br />✅ It stores everything using <strong>hash IDs</strong><br />✅ It connects files, folders, and commits like a <strong>chain</strong></p>
<h2 id="heading-the-git-folder-the-brain-of-your-repository">📁 The <code>.git</code> Folder: The Brain of Your Repository</h2>
<p>→When you run:</p>
<pre><code class="lang-plaintext">git init
</code></pre>
<p>→Git creates a hidden folder:</p>
<pre><code class="lang-plaintext">.git/
</code></pre>
<p>This folder stores <strong>everything Git needs</strong>:</p>
<p>✅ commit history<br />✅ branches<br />✅ staging data<br />✅ objects (files + folders + commits)</p>
<p>If you delete <code>.git</code> → your project becomes a normal folder again (no Git).</p>
<h2 id="heading-important-parts-inside-git">🗂️ Important Parts Inside <code>.git</code></h2>
<p>Here’s the most useful structure to remember:</p>
<pre><code class="lang-plaintext">.git/
 ├── objects/
 ├── refs/
 ├── HEAD
 ├── index
 └── config
</code></pre>
<h3 id="heading-meaning-in-simple-words">→Meaning in simple words</h3>
<p>✅ <strong>objects/</strong> → Git stores all data here (like files + commits)<br />✅ <strong>refs/</strong> → branches &amp; tags pointers<br />✅ <strong>HEAD</strong> → tells which branch you’re currently on<br />✅ <strong>index</strong> → staging area file<br />✅ <strong>config</strong> → repository settings</p>
<h2 id="heading-git-stores-everything-as-objects">Git Stores Everything as “Objects”</h2>
<p>Git has 3 main 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>These 3 things are enough to store a complete project history.</p>
<hr />
<h2 id="heading-1-blob-object-file-content">1) Blob Object = File Content</h2>
<p>→A <strong>Blob</strong> stores:</p>
<p>✅ only <strong>file content</strong><br />❌ not the file name</p>
<p>Example:<br />If your file <code>hello.txt</code> contains:</p>
<pre><code class="lang-plaintext">Hello Git
</code></pre>
<p>Git creates a blob for that content.</p>
<p>If another file has the same content, Git <strong>doesn’t store it again</strong>.</p>
<p>✅ Saves memory<br />✅ Super efficient</p>
<hr />
<h2 id="heading-2-tree-object-folder-structure">2) Tree Object = Folder Structure</h2>
<p>→A <strong>Tree</strong> stores:</p>
<p>✅ file names<br />✅ permissions<br />✅ link to blobs and other trees</p>
<p>Think of it like a folder map:</p>
<pre><code class="lang-plaintext">project/
 ├── index.html → blob
 ├── style.css  → blob
 └── src/       → tree
</code></pre>
<p>So tree is like <strong>directory structure</strong>.</p>
<hr />
<h2 id="heading-3-commit-object-full-snapshot-of-your-project">3) Commit Object = Full Snapshot of Your Project</h2>
<p>A commit stores:</p>
<p>✅ reference to a <strong>tree</strong><br />✅ message<br />✅ author<br />✅ date/time<br />✅ parent commit (previous snapshot)</p>
<p>Important:</p>
<blockquote>
<p>Commit does NOT store files directly<br />It points to a tree, and tree points to blobs</p>
</blockquote>
<h2 id="heading-best-mental-model-commit-tree-blob">Best Mental Model: Commit → Tree → Blob</h2>
<pre><code class="lang-plaintext">Commit
  ↓
Tree (folder structure)
  ↓
Blob (file content)
</code></pre>
<h2 id="heading-how-git-tracks-changes-the-truth"># How Git Tracks Changes (The Truth)</h2>
<p>Many beginners think:</p>
<p>❌ Git stores changes line-by-line<br />✅ Git stores <strong>snapshots</strong></p>
<p>Every commit is a <strong>full snapshot</strong>, but Git is smart:</p>
<ul>
<li><p>unchanged files reuse old blobs</p>
</li>
<li><p>only new file content becomes new blobs</p>
</li>
</ul>
<p>That’s why Git is fast even with many commits.</p>
<hr />
<h2 id="heading-what-happens-internally-when-you-run-git-add"># What Happens Internally When You Run <code>git add</code></h2>
<p>Command:</p>
<pre><code class="lang-plaintext">git add .
</code></pre>
<p>Git does this internally 👇</p>
<p>✅ Reads your changed file content<br />✅ Converts each file into a <strong>blob object</strong><br />✅ Stores blobs inside:</p>
<pre><code class="lang-plaintext">.git/objects/
</code></pre>
<p>✅ Updates the <strong>index (staging area)</strong></p>
<h3 id="heading-simple-meaning">✅ Simple meaning:</h3>
<blockquote>
<p><code>git add</code> = “Save changes to staging, ready to commit”</p>
</blockquote>
<hr />
<h2 id="heading-what-happens-internally-when-you-run-git-commit"># What Happens Internally When You Run <code>git commit</code></h2>
<p>Command:</p>
<pre><code class="lang-plaintext">git commit -m "done"
</code></pre>
<p>Git does this internally 👇</p>
<p>✅ Takes staged blobs from index<br />✅ Creates a <strong>tree object</strong> (snapshot structure)<br />✅ Creates a <strong>commit object</strong> (with metadata)<br />✅ Moves <code>HEAD</code> to latest commit</p>
<h3 id="heading-simple-meaning-1">✅ Simple meaning:</h3>
<blockquote>
<p><code>git commit</code> = “Save snapshot permanently to history”</p>
</blockquote>
<hr />
<h2 id="heading-git-uses-hashes-for-safety-why-its-reliable"># Git Uses Hashes for Safety (Why It’s Reliable)</h2>
<p>Git names every object using a hash like:</p>
<pre><code class="lang-plaintext">e83c5163316f89bfbde7d9ab23ca2e25604af290
</code></pre>
<p>This hash comes from:</p>
<p>✅ file content + object type + metadata</p>
<p>If you change even <strong>one character</strong>, the hash changes completely.</p>
<p>That’s why Git is secure because:</p>
<p>✅ No silent modification<br />✅ Integrity is guaranteed<br />✅ History is trustworthy</p>
<hr />
<h2 id="heading-git-workflow-the-perfect-mental-model">#Git Workflow (The Perfect Mental Model)</h2>
<p>Think of Git as 3 areas:</p>
<pre><code class="lang-plaintext">Working Directory → Staging Area → Repository
     (edit)           (add)           (commit)
</code></pre>
<h3 id="heading-example">Example:</h3>
<p>✅ Edit file → Working directory<br />✅ Add file → Stage it<br />✅ Commit → Save snapshot</p>
<p>This model will help you forever. No memorization needed.</p>
<h2 id="heading-final-conclusion">✅ Final Conclusion</h2>
<p>Git is not magic.</p>
<p>It is just a smart system that stores:</p>
<p>✅ file content as blobs<br />✅ folder structure as trees<br />✅ snapshots as commits<br />✅ everything linked by hashes</p>
<p>That’s why Git is:</p>
<p>🔥 Fast<br />🔥 Reliable<br />🔥 Perfect for collaboration<br />🔥 Industry mandatory</p>
<h1 id="heading-the-end"><strong>The End</strong></h1>
]]></content:encoded></item></channel></rss>