<?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[How Git Internally Work]]></title><description><![CDATA[How Git Internally Work]]></description><link>https://how-git-internlly-works-by-navdeep.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Fri, 18 Sep 2026 04:46:57 GMT</lastBuildDate><atom:link href="https://how-git-internlly-works-by-navdeep.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[Introduction :-
Today , I am learning Git and instead of memorizing the commands, suddenly my minds strikes and curious to know “ How Git internally works? “ When i researched on this i came to know that there is a folder named .git is not seen direc...]]></description><link>https://how-git-internlly-works-by-navdeep.hashnode.dev/inside-git-how-it-works-and-the-role-of-the-git-folder</link><guid isPermaLink="true">https://how-git-internlly-works-by-navdeep.hashnode.dev/inside-git-how-it-works-and-the-role-of-the-git-folder</guid><category><![CDATA[version control]]></category><category><![CDATA[Git]]></category><category><![CDATA[Git-Internals]]></category><category><![CDATA[blob_tree_commit]]></category><category><![CDATA[.git folder]]></category><dc:creator><![CDATA[Navdeep Rohilla]]></dc:creator><pubDate>Sat, 17 Jan 2026 13:28:31 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1768641778083/60b659b0-3ace-4165-bfde-4a951b25ddb1.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-introduction">Introduction :-</h2>
<p>Today , I am learning Git and instead of memorizing the commands, suddenly my minds strikes and curious to know “ How Git internally works? “ When i researched on this i came to know that there is a folder named .git is not seen directly in the folder because it is hidden. It is hidden because it stores some sensitive information about code like what and why the user changed the code. So after knowing this i feel more curious about How git works and the Role of the .git folder.</p>
<p>Now let’s move towards our today’s Topic “ Inside Git : How it works and the Role of the .git folder “.</p>
<p><img src="https://media.geeksforgeeks.org/wp-content/uploads/20250710172654460719/What-is-Git-repository.webp" alt="What-is-Git-repository" /></p>
<h2 id="heading-understanding-the-git-folder">Understanding the .git folder :-</h2>
<p>This folder is created when we initialise the git in our folder. But we can’t see it in the .git folder in our main folder because it is hidden .</p>
<p>We know the .git folder is the core of our repository it contains the metadata and the objects database for project’s version control history . It keep tracks changes . It is a hidden directory to prevent accidental modification or deletion, which would result in the loss of your project's entire history. </p>
<p>You can check .git folder by entring this command in powershell <code>ls -Force</code></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1768652852831/8af95349-0c10-4e35-8c04-679e59181cbe.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-key-components-of-the-git-folder">Key components of the .git folder :-</h3>
<p>These are the following files or directories which are in the .git folder :-</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1768652922750/3ae22f58-887a-45c8-9f67-113b3968a727.png" alt class="image--center mx-auto" /></p>
<p>Now let’s lear about them one by one :-</p>
<ol>
<li><p><code>objects/ :</code> This is Git’s object database , where all our projets’s content is stored . It contains :-</p>
<ul>
<li><p><strong>Blobs :</strong> The actual file contents.</p>
</li>
<li><p><strong>Trees :</strong> Representation of directories and file names</p>
</li>
<li><p><strong>Commits :</strong> Pointers to a specific tree (snapshot ) and its parent commits , forming the project history.</p>
</li>
<li><p>These objects are stored in a compressed format and referred to by thier unique SHA-1 hash values.</p>
</li>
</ul>
</li>
</ol>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1768653188889/62f3a262-54f1-4739-abcc-255b5d26970b.png" alt class="image--center mx-auto" /></p>
<ol start="2">
<li><p><code>refs/ :</code> This directory stores references (pointers) to commit objects , which help manage branches and tags.</p>
<ul>
<li><p><code>heads/ :</code> Contains pointers to the latest commit on each local branch.</p>
</li>
<li><p><code>remotes/ :</code> Contains pointers to the last - fetched state of remote branches (e.g from Github)</p>
</li>
<li><p><code>tags/ :</code> Contains pointers to specific commits that have been tagged.</p>
</li>
</ul>
</li>
<li><p><code>HEAD :</code> This file is a pointer that indicates which branch or commit yo are currently working on in our working directory.</p>
</li>
<li><p><code>index :</code> This binary file serves as the staging area (or index) , acting as an intermediary between your working directory and the repository. It tracks modification and prepares them for the next commit.</p>
</li>
<li><p><code>config :</code> This file contains repository - specific configuarations , such as the URL of the remote repository (e g on GitHub) , user information , and branch tracking settings.</p>
</li>
<li><p><code>hooks/ :</code> This directory contains customizable sripts that GIt runs automatically at certain points in the version control workflow, such as before a commit (pre- commit ) or after a push ( post-recieve ).</p>
</li>
<li><p><code>logs/ :</code> This folder maintains logs of changes made to branches and other references , including the reflogs , which sere as a safety net to recover lost commits</p>
</li>
</ol>
<h2 id="heading-git-objects-blob-tree-commit">Git objects : Blob , Tree ,Commit :-</h2>
<p>Git stores all of its data as aseries of immutable objects that link together to form a complete history of you project. The three main types of objects are blobs , trees , andcommits. Each object is identifies by a unique SHA-1 hash of its content.</p>
<h3 id="heading-blob-binary-large-object">Blob (Binary Large Object ) :-</h3>
<p>A blob object stores the raw contents of a single file.</p>
<ul>
<li><p><strong>Content:</strong> Just the file's data; it contains no metadata like the filename, creation date, or permissions.</p>
</li>
<li><p><strong>Purpose:</strong> To efficiently store file content. If two files in the repository (even in different commits or branches) have the same content, they will point to the same, single blob object, saving space through deduplication. </p>
</li>
</ul>
<h3 id="heading-tree">Tree :-</h3>
<p>A tree object represents a directory or sub-directory within the project's file structure. It essentially acts as a directory listing, mapping names and permissions to other objects. </p>
<ul>
<li><p><strong>Content:</strong> A list of entries, each containing:</p>
<ul>
<li><p>File mode (permissions like <code>100644</code> for a normal file)</p>
</li>
<li><p>Object type (either <code>blob</code> or <code>tree</code>)</p>
</li>
<li><p>The SHA-1 hash of the referenced object</p>
</li>
<li><p>The filename or directory name</p>
</li>
</ul>
</li>
<li><p><strong>Purpose:</strong> To organize blobs into a hierarchical file structure. A tree can reference both blobs (files) and other trees (subdirectories), creating a complete snapshot of the project's structure. </p>
</li>
</ul>
<h3 id="heading-commit">Commit :-</h3>
<p>A commit object represents a single, complete snapshot of your project at a specific point in time, along with associated metadata. </p>
<ul>
<li><p><strong>Content:</strong></p>
<ul>
<li><p>A pointer (SHA-1 hash) to the <strong>root tree</strong> of the entire project for that snapshot.</p>
</li>
<li><p>Pointers (SHA-1 hashes) to its <strong>parent commit(s)</strong>, which links the history together.</p>
</li>
<li><p>Author and committer information (name, email, and date).</p>
</li>
<li><p>A commit message describing the changes.</p>
</li>
</ul>
</li>
<li><p><strong>Purpose:</strong> To link the project's state (the tree) to its history and provide context for the changes. The chain of parent pointers forms a directed acyclic graph (DAG), which is the foundation of Git's version control capabilities. </p>
</li>
</ul>
<h2 id="heading-how-git-track-changes">How git Track Changes :-</h2>
<p>Git track changes by using a content - addressable filesystem and a three - state model (working directory , staging area , and local repository) , primarily relying on unique SHA-1 hashes to identify and store file contents.</p>
<ul>
<li><p><strong>Content Addressing (SHA-1 Hashes):</strong> Git doesn't track files by name and store a list of differences (deltas) for each change; instead, it tracks the <em>entire content</em> of files. When a file is added or changed, Git calculates a unique 40-character SHA-1 hash of its contents. This hash acts as a unique identifier and is used to store the content as a "blob" object in a hidden <code>.git/objects</code> directory.</p>
</li>
<li><p><strong>Snapshots, not Diffs:</strong> A "commit" in Git is a complete snapshot of your project at a specific point in time, not just the changes since the last commit. This snapshot (a "commit object") contains metadata (author, committer, message, timestamp) and a reference to a "tree object". The tree object maps filenames and directory structures to their corresponding content "blob" hashes.</p>
</li>
<li><p><strong>Efficiency:</strong> While Git logically stores full snapshots, it is highly efficient. If a file's content hasn't changed between commits, Git simply reuses the reference to the existing blob object, storing the content only once. Space-saving optimizations, such as delta compression, are applied periodically during garbage collection (<code>git gc</code>) to further reduce the repository's size.</p>
</li>
<li><p><strong>The Index (Staging Area):</strong> A key component is the "index" or "staging area".</p>
<ul>
<li><p>To quickly detect if a file has changed in the working directory, Git initially checks file metadata like size and modification time against the data cached in the index.</p>
</li>
<li><p>Running <code>git add</code> calculates the hash of a modified file and places the new blob object into the database, updating the index with this new hash.</p>
</li>
<li><p>Running <code>git commit</code> then creates a permanent commit based on exactly what is in the staging area at that moment. </p>
</li>
</ul>
</li>
</ul>
<h2 id="heading-conclusion">Conclusion :-</h2>
<p>Understanding how Git works internally makes Git feel <strong>simple and logical</strong>, not confusing.<br />Instead of just memorizing commands, we learned <strong>what actually happens behind the scenes</strong>.</p>
<p>We saw that the <code>.git</code> folder is the heart of a Git repository. It stores everything Git needs—file content, project structure, commit history, and metadata. Git does not track files by name or line-by-line differences. Instead, it tracks <strong>file content using SHA-1 hashes</strong> and saves the project as <strong>snapshots</strong> using blobs, trees, and commits.</p>
<p>We also understood the importance of the <strong>three-state model</strong>—working directory, staging area, and local repository—which gives us full control over what changes go into each commit.</p>
<p>Once you understand these internal concepts, Git commands start making sense automatically.<br />You no longer use Git blindly—you use it <strong>with confidence and clarity</strong>.</p>
<p>Don’t just learn Git commands.<br /><strong>Understand Git—and it will stay with you forever.</strong></p>
]]></content:encoded></item></channel></rss>