<?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" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Manthan Sharma on Medium]]></title>
        <description><![CDATA[Stories by Manthan Sharma on Medium]]></description>
        <link>https://medium.com/@manthannaruto10?source=rss-806eb8ca5d00------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*UKp_UsTCiVBGpgUq</url>
            <title>Stories by Manthan Sharma on Medium</title>
            <link>https://medium.com/@manthannaruto10?source=rss-806eb8ca5d00------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 06:35:42 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@manthannaruto10/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Git Is Just Three Simple Ideas]]></title>
            <link>https://medium.com/@manthannaruto10/git-is-just-three-simple-ideas-8df3cf1ec556?source=rss-806eb8ca5d00------2</link>
            <guid isPermaLink="false">https://medium.com/p/8df3cf1ec556</guid>
            <category><![CDATA[github-actions]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[git-commands]]></category>
            <category><![CDATA[blogging]]></category>
            <category><![CDATA[hashmap]]></category>
            <dc:creator><![CDATA[Manthan Sharma]]></dc:creator>
            <pubDate>Wed, 04 Nov 2026 05:54:55 GMT</pubDate>
            <atom:updated>2026-11-04T05:54:55.146Z</atom:updated>
            <content:encoded><![CDATA[<h3>Why Git feels like magic</h3><p>Ever typed git reset --hard and held your breath? Git feels like a box of spells because we never see what&#39;s inside.</p><p>Here’s the secret: Git is just three simple ideas stacked together. Learn them once and every command starts to make sense.</p><p>Think of Git as a library with an unusual rule: every book is shelved under a fingerprint of its own pages, not under its title. Change one word, and it becomes a different book on a different shelf. The old one is still there.</p><p>In this post we’ll open the hidden .git folder and see that rule in action, using real commands you can paste into your own terminal.</p><h3>Idea 1: everything gets a fingerprint</h3><p>Git never stores a file by its name. It stores the content and names it by its SHA-1 hash, a 40-character fingerprint.</p><pre>$ echo &quot;hello git&quot; | git hash-object --stdin<br>8d0e41234f24b6da002d962a26c2495ea16a425f</pre><p>Run that on any computer and you get the exact same hash. Same content, same name, everywhere. So duplicate files are stored only once, and corruption is caught instantly because the content no longer matches its name.</p><p>There’s no secret sauce in that hash. Git adds a tiny header (the type, the size, and a null byte) in front of your content and runs SHA-1. You can reproduce it without Git at all:</p><pre>$ printf &#39;blob 10\0hello git\n&#39; | sha1sum<br>8d0e41234f24b6da002d962a26c2495ea16a425f  -</pre><p>Git then compresses the content and saves it as .git/objects/8d/0e4123…. The first two characters become a folder name so no single folder gets too crowded.</p><p>Git needs just three kinds of these objects:</p><ul><li><strong>blob</strong> (a file): just the bytes, not even the filename</li><li><strong>tree</strong> (a folder): names pointing to blobs and other trees</li><li><strong>commit</strong> (a save point): one tree, its parent commit, author, message</li></ul><p>Notice that a blob doesn’t know its own filename. Names live in trees. That’s why renaming a file is cheap: the blob stays the same, only the tree changes.</p><p>You can peek inside any object with git cat-file -p. Here&#39;s a small project with a README.md and a src/app.js:</p><pre>$ git cat-file -p HEAD            # the commit<br>tree 08fbf9b361f06821a00135cfa3dfcdc87d2f65e1<br>author Ada &lt;ada@example.com&gt; 1793680200 +0530</pre><pre>first commit</pre><pre>$ git cat-file -p HEAD^{tree}     # the root folder<br>100644 blob 8d0e412...    README.md<br>040000 tree d33487c...    src</pre><p>The commit points to a tree, the tree points to a blob and another tree. Follow the chain and you reach every file exactly as it was when you committed.</p><h3>Idea 2: Change one line, and every folder above it changes</h3><p>A folder’s hash is built from the hashes of everything inside it. This structure is called a Merkle tree. Edit one line in app.js, commit, and watch the change ripple upward:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Zo0V7U4T99Dggmx932Sedw.png" /></figure><p>README.md didn&#39;t change, so both commits share the exact same blob. That&#39;s how Git keeps a full snapshot of every commit without your repo exploding in size.</p><p>This ripple effect gives Git two superpowers:</p><ul><li><strong>Fast comparisons.</strong> If two folders have the same hash, they are identical. Git can skip them without opening a single file, which is a big reason git status stays quick even in huge projects.</li><li><strong>Tamper-proof history.</strong> A commit’s hash depends on its root tree, so nobody can quietly edit an old file. Every hash above it would change, and everyone would notice.</li></ul><h3>Idea 3: History is a graph, Branches are sticky notes</h3><p>Every commit points back to its parent. A merge commit simply has two parents. Arrows only go backwards in time, so history forms a DAG (directed acyclic graph).</p><p>Think of it like a family tree, drawn backwards. Each child knows its parents, but parents never know their children. Here’s what happens when we create a feature branch, commit on both sides, and merge:</p><figure><img alt="MERGE FLOW CHART" src="https://cdn-images-1.medium.com/max/1024/1*bEdCrQqjZXnc0512wxfvzg.png" /></figure><p>And a branch? It’s literally a text file with one hash inside:</p><pre>$ cat .git/refs/heads/feature<br>6e05986bd0a753cb00c309621d919911270859e2</pre><p>That’s why creating a branch is instant, and why deleting one never deletes your commits.</p><p>HEAD is one more sticky note. It tells Git which branch you&#39;re on right now:</p><pre>$ cat .git/HEAD<br>ref: refs/heads/main</pre><p>Merging is graph work too. Git finds the <strong>merge base</strong>, the nearest commit both branches share (here b3c010f), checks what each side changed since then, and combines the two into a new commit with two parents.</p><h3>Putting it together: add, then commit</h3><p>git add saves your file contents as objects. git commit wraps them into trees, writes a commit, and moves your branch forward.</p><figure><img alt="HASH/BRANCH FLOW CHART" src="https://cdn-images-1.medium.com/max/1024/1*9B0fL5yBG_xWUv7FPCOPCQ.png" /></figure><p>Notice the last step: a commit is officially “done” the moment one tiny pointer moves.</p><p>The middle stop is the <strong>index</strong>, also called the staging area. It’s a file at .git/index that works like a draft of your next commit: a list of every path and the blob hash it should point to.</p><p>You can watch it happen. Right after git add, the blobs already exist, even though no commit does yet:</p><pre>$ git add .<br>$ git count-objects<br>2 objects        # README.md and app.js blobs</pre><pre>$ git commit -m &quot;first commit&quot;<br>$ git count-objects<br>5 objects        # + root tree, src tree, the commit</pre><h3>Fun fact: Diffs are Never Saved</h3><p>Git stores snapshots, not changes. Every time you run git diff, it compares two versions on the spot and finds the smallest set of - and + lines that turns one into the other.</p><pre>$ git diff --no-index a.txt b.txt<br>-A<br>-B<br> C<br>-A<br> B<br>+A<br> B<br> A<br>+C</pre><p>The unmarked lines (C, B, B, A) are the longest part both files share. Everything else is 3 deletions + 2 additions = 5 edits, the minimum possible.</p><p>The algorithm behind this is <strong>Myers diff</strong>, a fast cousin of Longest Common Subsequence. It tries 0 edits, then 1, then 2, and stops at the first one that works. Since most commits change only a few lines, diffs feel instant.</p><p>A handy way to picture it: lay file A along the top of a grid and file B down the side. Moving right deletes a line, moving down adds one, and moving diagonally (where lines match) is free. The best diff is simply the shortest path from one corner to the other.</p><p>Git also ships alternatives. git diff --histogram and git diff --patience first lock onto lines that appear only once, which often gives cleaner results when you&#39;ve moved a block of code around.</p><h3>Bonus: Draw your own Contribution Graph</h3><p>That green grid on GitHub is just commits counted by date. Git can give you the numbers in one line:</p><pre>git log --format=&#39;%as&#39; | sort | uniq -c</pre><p>%as prints each commit&#39;s author date, sort groups the same days together, and uniq -c counts them. Since this only reads commit objects, you don&#39;t even need the project&#39;s files. A treeless clone downloads just the history graph:</p><pre>git clone --bare --filter=tree:0 https://github.com/vitejs/vite.git</pre><p>Here’s the real result for Vite over the last year:</p><figure><img alt="GIT COMMIT CONTRIBUTION TAB/CALENDER" src="https://cdn-images-1.medium.com/max/1024/1*EH2lbjzJuIK-1wqXapJPBw.png" /></figure><p>Almost nothing on weekends. Run it on your own repo and see what your coding habits look like.</p><h3>Cheat sheet: what commands really do</h3><ul><li>git add — saves file contents as blobs and records them in the index</li><li>git commit — writes trees and a commit, then moves the branch</li><li>git branch x — creates a tiny file holding one hash</li><li>git switch x — points HEAD at a different branch and updates your files</li><li>git merge x — finds the merge base and writes a commit with two parents</li><li>git rebase — copies commits onto a new parent, creating new hashes</li><li>git reset --hard — moves a pointer back; old commits still exist</li><li>git reflog — shows where pointers used to be, so you can undo almost anything</li></ul><p>Next time a Git command scares you, ask two questions: which objects get created, and which pointer moves? That’s the whole trick.</p><p>To keep exploring, open the .git folder in any project and run git cat-file -p on a hash you find there. Ten minutes of poking around will teach you more about Git than any list of commands.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8df3cf1ec556" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>