<?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 Beginners: Basics and Ess. Commands]]></title><description><![CDATA[Git Beginners: Basics and Ess. Commands]]></description><link>https://gitbeginnerbypiyush.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Thu, 15 Oct 2026 14:48:39 GMT</lastBuildDate><atom:link href="https://gitbeginnerbypiyush.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 work internally
When you run a command:git initGit creates a hidden folder:.git/
This folder is the entire version control system for your project. Your project files are just working data. The .git folder contains:

History: The complete rec...]]></description><link>https://gitbeginnerbypiyush.hashnode.dev/inside-git-how-it-works-and-the-role-of-the-git-folder</link><guid isPermaLink="true">https://gitbeginnerbypiyush.hashnode.dev/inside-git-how-it-works-and-the-role-of-the-git-folder</guid><category><![CDATA[Cohort2026]]></category><category><![CDATA[cohort]]></category><category><![CDATA[Git]]></category><category><![CDATA[GitHub]]></category><category><![CDATA[GitLab]]></category><category><![CDATA[Gitcommands]]></category><dc:creator><![CDATA[Piyush]]></dc:creator><pubDate>Tue, 27 Jan 2026 09:21:11 GMT</pubDate><content:encoded><![CDATA[<h2 id="heading-how-git-work-internally">How git work internally</h2>
<p>When you run a command:<br /><code>git init</code><br />Git creates a hidden folder:<br /><code>.git/</code></p>
<p>This folder is the entire <strong>version control system</strong> for your project. Your project files are just working data. The <code>.git</code> folder contains:</p>
<ul>
<li><p><strong>History:</strong> The complete record of all changes made to project over time (every commits).</p>
</li>
<li><p><strong>Branches:</strong> These are mainly movable pointers to commits. It let us work on different version of projects in parallel.</p>
</li>
<li><p><strong>Metadata:</strong> Git stores extra information about the project, like author, name, email, commit time, config settings and messages.</p>
</li>
</ul>
<p><strong>Object Database:</strong> The storage system inside <code>.git/objects</code> where Git saves all blobs, trees, and commits using hashes.</p>
<h2 id="heading-high-level-structure-of-git">High-level structure of <code>.git</code></h2>
<pre><code class="lang-bash">├── HEAD  
├── config  
├── index  
├── objects/  
│   ├── ab/  
│   └── f3/  
├── refs/  
│   ├── heads/  
│   └── tags/
</code></pre>
<p>There are 6 separate files/folder in the <code>.git</code> folder. Each file or folder has their own task to perform to make Git work efficiently.</p>
<h2 id="heading-git-objects-blob-tree-commit-the-dna-of-git">Git Objects: Blob, Tree, Commit (The DNA of Git).</h2>
<p>Everything in Git is stored as an <strong>Object</strong>. There are three main types of Objects:</p>
<ol>
<li><strong>Blob (File Content):</strong> A Blob stores the content of a file nots its name. For example we have a file <code>index.html</code>.<br /> It will store the content: <code>Hello World</code><br /> The content becomes a blob with hash like:<br /> <code>3b18e512dba79e4c8300dd08aeb37f8e728b8dad</code></li>
</ol>
<blockquote>
<p>if two files have identical content - they share the same blob.</p>
</blockquote>
<ol start="2">
<li><p><strong>Tree (Folder Structure):</strong> A tree object represents a directory. It stores.</p>
<ul>
<li><p>File Names</p>
</li>
<li><p>Subfolders</p>
</li>
<li><p>Which blob belongs to which name</p>
</li>
</ul>
</li>
</ol>
<p>Example tree:</p>
<pre><code class="lang-bash">├── index.html (blob A)  
├── app.js (blob B)   
└── src/   
        └── utils.js (blob C)
</code></pre>
<ol start="3">
<li><strong>Commit:</strong> A commit is a saved snapshot of your project, along with details like message, author, and a link to previous commit.</li>
</ol>
<blockquote>
<p>This Below diagram is a Gits Actual Data Model.</p>
</blockquote>
<pre><code class="lang-bash">Commit
│
└── Tree
      ├── Blob (index.html)
      ├── Blob (app.js)
      └── Tree (src/)
            └── Blob (utils.js)
</code></pre>
<h2 id="heading-how-git-track-changes">How Git Track Changes.</h2>
<p>Git has three layers: <code>Working Directory → Staging Area → Repository</code></p>
<ol>
<li><p><strong>Working Directory:</strong> In this normally files are stored.</p>
</li>
<li><p><strong>Staging area</strong> <code>(.git/index)</code><strong>:</strong> A temporary area where Git prepares the next commit.</p>
</li>
<li><p><strong>Repository</strong> <code>(.git/objects)</code>: The permanent object database.</p>
</li>
</ol>
<h2 id="heading-git-command-internals">Git Command Internals.</h2>
<p>Lets dive into the two important Git Commands <code>git add</code> and <code>git commit -m</code>.</p>
<h3 id="heading-what-really-happens-during-git-add">What really happens during <code>git add</code></h3>
<p>When you run a git command: <code>git add file.txt</code></p>
<p><strong>Step by Step(internally):</strong></p>
<ol>
<li><p><strong>Git reads the file content:</strong> Git opens <code>file.txt</code> and read its exact content(not the file name).</p>
</li>
<li><p><strong>Git creates a hash of content:</strong> It generates a Hash code based on the content. This hash becomes the <strong>unique ID</strong> of that version of the file.</p>
</li>
<li><p><strong>Git creates a blob object:</strong> Git stores that content as a <strong>blob object</strong> inside: <code>.git/objects/</code></p>
</li>
<li><p><strong>Git updates the Staging area (index):</strong> Git updates the <code>.git/index</code> file.</p>
</li>
</ol>
<blockquote>
<p><code>git add</code> = convert file → blob → store it → prepare task for commit.</p>
</blockquote>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1768370126495/f9393337-e3c3-406a-948d-add1421786c3.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-what-really-happens-during-git-commit">What really happens during <code>git commit</code></h3>
<p>Lets decode when you write a command: <code>git commit -m “My message”</code></p>
<p><strong>Step by Step(internally):</strong></p>
<ol>
<li><strong>Git Reads the Staging area:</strong> it does not look the working directory it reads only from <code>.git/index</code> (staging area).</li>
</ol>
<blockquote>
<p>staged task = will be committed.<br />not staged = will be ignored</p>
</blockquote>
<ol start="2">
<li><p><strong>Tree Objects:</strong> Using the staged files, Git built a tree objects.</p>
<p> This tree represents:</p>
<ul>
<li><p>Folder Structure</p>
</li>
<li><p>File names</p>
</li>
<li><p>Which blob belongs to which file</p>
</li>
</ul>
</li>
</ol>
<pre><code class="lang-bash">    Tree
    ├── index.html → blob a1b2
    ├── app.js     → blob c3d4
    └── src/
        └── utils.js → blob e5f6
</code></pre>
<ol start="3">
<li><strong>Git creates a Commit object</strong>: Now Git creates a commit object that stores:</li>
</ol>
<ul>
<li><p>Hash of the tree</p>
</li>
<li><p>Parent commit hash</p>
</li>
<li><p>Author + timestamp</p>
</li>
<li><p>Commit message</p>
</li>
</ul>
<pre><code class="lang-bash">commit
  → tree <span class="hljs-built_in">hash</span>
  → parent <span class="hljs-built_in">hash</span>
  → metadata
</code></pre>
<ol start="4">
<li><strong>Git updates HEAD and branch pointer:</strong> Finally Git updates</li>
</ol>
<ul>
<li><p><code>HEAD</code></p>
</li>
<li><p>Current branch (like <code>main</code>)</p>
</li>
</ul>
<blockquote>
<p>This is why: The new commit becomes the latest version.</p>
<p><code>git commit</code> converts the staged index into a tree object, wraps it into a commit object with metadata and parent reference, and updates HEAD to point to the new commit.</p>
</blockquote>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1768400994951/5acfe6d5-f76f-4476-9693-d17b93e12d74.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-how-git-uses-hash-to-ensure-integrity">How Git uses Hash to ensure integrity</h2>
<p>Git uses <strong>hashes</strong> as unique fingerprint for everything its stores: files, folder and commits<br />Whenever Git stores Something it:</p>
<ol>
<li><p>Takes the content.</p>
</li>
<li><p>Run a hashing algorithm</p>
</li>
<li><p>Generate a unique hashing like: <code>f3a1c9b2e7...</code></p>
</li>
</ol>
<p>What it means:</p>
<ul>
<li><p>If content changes → hash changes</p>
</li>
<li><p>If a file is modified → its blob hash changes.</p>
</li>
<li><p>If a commit is altered → commit hash changes</p>
</li>
</ul>
<blockquote>
<p>So Git can confidently guarantee: What you committed yesterday is exactly the same today.<br />Hash = tamper-proof-id of content.</p>
</blockquote>
<pre><code class="lang-bash">Commit 1 → Commit 2 → Commit 3 → Commit 4
                                ↑
                              HEAD
</code></pre>
<blockquote>
<p>This article delves into the internal workings of Git, explaining how it manages version control through the hidden `.git/` folder. It covers the role of Git objects like blobs, trees, and commits in storing file contents and project snapshots. The guide further explores Git commands like `git add` and `git commit -m`, detailing their internal processes. It also highlights Git's use of hashes to ensure data integrity, emphasizing how changes in content lead to different hashes, thereby guaranteeing the authenticity of your version history.</p>
</blockquote>
]]></content:encoded></item></channel></rss>