<?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 Sewwandi Harishchandra  on Medium]]></title>
        <description><![CDATA[Stories by Sewwandi Harishchandra  on Medium]]></description>
        <link>https://medium.com/@harishchandrads98?source=rss-f3a7da75a19c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*x0icoIhXXK7b8fZz</url>
            <title>Stories by Sewwandi Harishchandra  on Medium</title>
            <link>https://medium.com/@harishchandrads98?source=rss-f3a7da75a19c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 01:34:00 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@harishchandrads98/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[I Went From Git Disaster to Git Pro: The Guide I Wish Someone Gave Me on Day 1]]></title>
            <link>https://medium.com/@harishchandrads98/i-went-from-git-disaster-to-git-pro-the-guide-i-wish-someone-gave-me-on-day-1-2f8a36110ac1?source=rss-f3a7da75a19c------2</link>
            <guid isPermaLink="false">https://medium.com/p/2f8a36110ac1</guid>
            <category><![CDATA[version-control]]></category>
            <category><![CDATA[team-collaboration]]></category>
            <category><![CDATA[git]]></category>
            <category><![CDATA[version-control-system]]></category>
            <category><![CDATA[github]]></category>
            <dc:creator><![CDATA[Sewwandi Harishchandra ]]></dc:creator>
            <pubDate>Fri, 26 Dec 2025 08:19:53 GMT</pubDate>
            <atom:updated>2025-12-31T13:07:36.190Z</atom:updated>
            <content:encoded><![CDATA[<p>If you’re a developer just starting your career — or someone still battling those confusing, frustrating Git issues — this article is for you.<br>I’ve been there too.</p><p>Consider this your step-by-step road map to finally working with Git confidently and correctly, without breaking the repository or your sanity.</p><p>Let’s dive in!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6SpyP-JYeqbOz8VciyEaJQ.png" /></figure><h4>What is Git (And Why Should You Care)?</h4><p>Git is a distributed version control system. Translation? It’s the tool that prevents your team from accidentally deleting each other’s work.<br>Here’s the scenario: You’re working on a feature. Your colleague is fixing a bug. You both need to change the same code base. Without Git, you’d be emailing files back and forth like it’s 1999, praying nobody overwrites anyone else’s changes.</p><p><strong>Git solves this by:</strong></p><ol><li>Tracking every change made to your code (who, what, when, why).</li><li>Letting everyone work simultaneously on different features without chaos.</li><li>Merging changes intelligently so your work and your colleague’s work combine properly.</li><li>Giving you a time machine to undo mistakes (trust me, you’ll need this)</li></ol><p>The “distributed” part means everyone has the complete history of the project on their machine. No single point of failure. No “the server is down so nobody can work” nonsense.</p><h4>The Mistakes I Made</h4><p><strong>My most embarrassing Git moment</strong></p><p>My company uses a rebase workflow. During my internship, I developed a feature and opened my pull request. Conflicts everywhere. No problem — I’d learned about rebasing!</p><p>I carefully rebased my branch onto main, resolved all the conflicts, and felt like a Git wizard. Then came the moment to push my changes:</p><pre>$ git push<br>hint: Updates were rejected because the tip of your current branch is behind<br>hint: its remote counterpart. If you want to integrate the remote changes,<br>hint: use &#39;git pull&#39; before pushing again.<br>hint: See the &#39;Note about fast-forwards&#39; in &#39;git push --help&#39; for details</pre><p>I panicked.</p><p>I knew about git push --force.I&#39;d seen the warnings everywhere: <strong>&quot;Never force push! You&#39;ll destroy everything!&quot;</strong></p><p>So I froze. For hours. I googled frantically. I stared at my terminal.</p><p>Finally, a senior dev told me: <em>“Just force push. It’s YOUR branch. Nobody else is working on it.”</em></p><pre>$ git push --force</pre><p>It worked. Instantly. The PR merged.</p><p><strong>What I learned:</strong></p><p>The error message was misleading. My remote branch wasn’t “ahead” — it had <strong>diverged</strong> because rebasing rewrites commit history. My local commits were technically “new” commits (with new IDs), even though the code was the same.</p><p>git push --force isn&#39;t evil. It&#39;s a tool. The rule isn&#39;t &quot;never force push&quot; — it&#39;s:</p><p>✅ <strong>Safe to force push:</strong> On YOUR feature branch that only you work on</p><p>❌ <strong>Never force push:</strong> On shared branches like main or branches others are using</p><p>That day, I didn’t just learn a Git command. I learned that <strong>understanding the “why” behind the rules is more important than blindly following them.</strong></p><h3><strong>The Mental Models That Changed Everything</strong></h3><h4><strong>Think of commits as snapshots, not diffs</strong></h4><p>Here’s the shift that made everything click: <strong>commits are snapshots, not diffs.</strong></p><p>I used to think a commit was just ‘the changes I made’. Wrong. A commit is a complete photograph of your entire project at that moment in time.</p><p>This explains why branching is so fast (you’re just creating a pointer to a snapshot), why you can switch between branches instantly, and why Git can show you any version of your code without rebuilding it from scratch.</p><p>Once I understood this, commands like git checkout, git branch, and git merge finally made sense.</p><h4><strong>Branches are just pointers</strong></h4><p>I used to think creating a branch meant Git was copying my entire codebase. Wrong!</p><p>A branch is just a <strong>41-byte pointer</strong> to a commit. That’s it. A tiny label that says “this commit is the tip of my feature.”</p><p>When you run git branch new-feature, Git doesn&#39;t copy files. It creates a single tiny file that points to a commit ID. Done. Instant. Free.</p><p>This explains:</p><ul><li>Why creating 100 branches takes milliseconds</li><li>Why switching branches is so fast</li><li>Why deleting a branch doesn’t delete your code</li><li>Why Git is so different from older systems like SVN</li></ul><p>Once I understood this, I stopped being scared of branches. Now I create them constantly — for every feature, every experiment, every “let me try this crazy idea.”</p><p>Branches are cheap. Use them liberally.</p><h4><strong>Remote vs Local Repositories: The Two Worlds of Git</strong></h4><p>This was one of the biggest “aha!” moments for me: <strong>Git operates in two separate places.</strong></p><p><strong>Local Repository = Your Personal Workspace</strong></p><p>This is the .git folder on your computer. It&#39;s a <strong>complete, standalone copy</strong> of the entire project history. You can work offline, make commits, create branches, time-travel through history — all without an internet connection.</p><p>When you run commands like:</p><ul><li>git add — stage files locally</li><li>git commit — save a snapshot locally</li><li>git checkout / git switch — switch branches locally</li><li>git log — view local history</li><li>git branch — create/delete local branches</li></ul><p><strong>Nothing leaves your machine.</strong> You’re working in your private workspace.</p><p><strong>Remote Repository = The Shared Source of Truth</strong></p><p>This is typically on GitHub, GitLab, Bitbucket, or your company’s server. It’s where your team <strong>collaborates</strong> and <strong>synchronizes</strong> work.</p><p>The remote is usually called origin (that&#39;s just a convention, a nickname for the URL).</p><h4>The Bridge Between Local and Remote</h4><p>Here’s where beginners get confused. <strong>Your local repository and the remote repository don’t automatically sync.</strong> You have to explicitly move data between them:</p><p><strong>Receiving changes from remote → local:</strong></p><ul><li>git fetch — Downloads commits from remote, doesn’t change your files.</li><li>git pull — Downloads commits AND merges them into your current branch (pull = fetch + merge).</li></ul><p><strong>Sending changes from local → remote:</strong></p><ul><li>git push — Uploads your local commits to the remote</li></ul><h4>Key Insights:</h4><h4>Your local repo is complete and independent</h4><p>You have the FULL history, not just the latest version<br>You can commit, branch, and work entirely offline<br>This is what “distributed” means — no single point of failure</p><p>Remote branches are different from local branches</p><pre>main              # Your local main branch<br>origin/main       # The remote main branch (as last fetched)</pre><p>These are separate pointers that can diverge!</p><p>“origin” is just a nickname</p><pre>$ git remote -v<br>  origin  https://github.com/company/project.git</pre><p>“origin” is shorthand so you don’t have to type the full URL every time</p><p><strong>You can have multiple remotes</strong></p><pre>origin     # Your company&#39;s repository<br>upstream   # The original project (if you forked)<br>backup     # Your personal backup server</pre><pre>Common Confusion Points:</pre><pre>❌ <strong>Wrong</strong>: &quot;I committed my code, so my team can see it now&quot;<br>✅ <strong>Right</strong>: &quot;I committed locally. Now I need to push so my team can see it.&quot;</pre><pre>❌ <strong>Wrong</strong>: &quot;git pull is the opposite of git push&quot;<br>✅ <strong>Right</strong>: &quot;git push uploads. git pull downloads AND merges. The opposite of push is actually fetch.&quot;</pre><pre>❌ <strong>Wrong</strong>: &quot;The remote is the &#39;real&#39; repository&quot;<br>✅ <strong>Right</strong>: &quot;Both local and remote are complete, valid repositories. Remote is just where we agree to synchronize.&quot;</pre><pre>Why This Matters:</pre><pre>Understanding the local/remote split explains:<br>- Why you can work offline for days, then push everything at once<br>- Why `git status` shows &quot;Your branch is ahead of &#39;origin/main&#39; by 3 commits&quot;<br>- Why force pushing is dangerous (you&#39;re overwriting the shared repository)<br>- Why you need to pull before pushing (to avoid conflicts with others&#39; work)<br>- Why deleting a local branch doesn&#39;t delete it from the remote</pre><pre>Your Computer                          GitHub Server<br>┌─────────────────┐                   ┌──────────────────┐<br>│ Local Repo      │                   │ Remote Repo      │<br>│                 │                   │                  │<br>│ main: A-B-C-D-E │  git push →       │ main: A-B-C      │<br>│                 │                   │                  │<br>│ feature: A-B-F  │  git push →       │ feature: (none)  │<br>└─────────────────┘                   └──────────────────┘<br>        ↑<br>    git add, git commit<br>    (all local operations)</pre><pre>After git push:<br>Your Computer                          GitHub Server<br>┌─────────────────┐                   ┌──────────────────┐<br>│ Local Repo      │                   │ Remote Repo      │<br>│                 │                   │                  │<br>│ main: A-B-C-D-E │  ← synced →       │ main: A-B-C-D-E  │<br>│                 │                   │                  │<br>│ feature: A-B-F  │  ← synced →       │ feature: A-B-F   │<br>└─────────────────┘                   └──────────────────┘</pre><p><strong>The “Remote Tracking Branch” Concept:</strong></p><pre>$ git branch -a<br>* main                    # Your local branch<br>  feature                 # Your local branch<br>  remotes/origin/main     # Reference to remote main<br>  remotes/origin/feature  # Reference to remote feature</pre><p>Those remotes/origin/* branches are <strong>local copies of what the remote looked like last time you fetched.</strong> They&#39;re snapshots, not live connections.</p><p>When you git fetch, Git updates these references. When you git push, Git updates the actual remote, then updates these references.</p><h3>The Commands That Actually Matter (The 20% You’ll Use 80% of the Time)</h3><p>There are plenty of commands in git. But, you will be using only few of them on daily basis. Here are some useful git commands I used (escaped me from several nightmares).</p><h4>git status — Your Best Friend</h4><p>To check what’s happening right now in your repository, run git status. This command displays</p><ul><li>Your current branch</li><li>All the staged, not staged, and untracked files</li><li>Whether you’re ahead/behind the remote.</li></ul><pre>$ git status</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/841/1*nQQfYMfA_U1hsSC4sPR9rg.png" /></figure><p><em>The Golden Rule:</em> When in doubt, run git status. It’s impossible to break Git if you read what it tells you.</p><h4>git branch — Create branch</h4><p>This is used for branching. For every feature, every bugfix you will be creating a new branch and you will be doing changes in that branch for the specific feature/fix.</p><p>Earlier, we discussed what is a branch. So, don’t be afraid to create as many branches as you want!</p><h4>git checkout / git switch— Navigate Branches</h4><p>git checkout is used for switch between the branches or commits. See following commands.</p><pre>$ git checkout &lt;branch-name&gt;<br># Switch to that specific branch.<br><br>$ git switch &lt;branch-name&gt;<br># Switch to that specific branch.</pre><pre>$ git checkout &lt;commit-hash&gt;<br># Switch to the snapshot of that specific commit.<br><br>$ git switch &lt;commit-hash&gt;<br># Switch to the snapshot of that specific commit.</pre><p>You can use it to create a new branch and switch to it.</p><pre>$ git checkout -b &lt;new-branch-name&gt;<br># -b for creating new branch.<br># Create &lt;new-branch-name&gt; and switch to it.</pre><h4>git add — Stage your changes</h4><p>This is used to add your changes to git. This is called staging.</p><pre>$ git add &lt;file-name&gt; <br># Stage the file to git.<br><br>$ git add .           <br># Stage all the changes you have done so far at once.</pre><h4>git commit — Save a snapshot</h4><p>This is where the magic starts. When you stage the changes, you can save a snapshot of your work in the git by committing changes.</p><pre>$ git commit -m &quot;summary of changes in a simple message&quot;</pre><h4>git push — Share Your Work</h4><p>This is where you actually share your work. All the steps your have done earlier just saved a snapshot your work locally. Until you push, your colleagues cannot see your work. It stays only on your computer.</p><pre>$ git push -u origin &lt;your-branch-name&gt;</pre><h4>git rebase — Keep History Clean</h4><p>This is the command you use when your work conflicts with someone else’s or with the main branch. Imagine you edited a line in a file. Meantime, someone else has edited the same line and merged it into the main branch. Now, you don’t have that change. Therefore, when you try to merge your work to the main branch, there will be a conflict as someone has changed the same line.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*GIIi6WV7YEsupBQRNOUHPQ.png" /></figure><p>This is where git rebase comes in handy.</p><p>All you need to do is to follow these simple steps.</p><pre>$ git checkout main <br># Swich to the main branch.<br><br>$ git pull origin main<br># Download and merge the latest changes in the main branch.<br><br># Now, you need to place all your changes on top of these latest changes.<br><br>$ git checkout &lt;your-branch-name&gt;<br># Switch back to your branch.<br><br>$ git rebase main<br># Make the latest main branch as the new base of your current branch and <br># bring all your commits on top of that.</pre><p>Now, you will see a message in the command line like</p><pre>CONFLICT (content): Merge conflict in &lt;file-name&gt;<br>error: could not apply e71129b... Merge conflicts<br>hint: Resolve all conflicts manually, mark them as resolved with<br>hint: &quot;git add/rm &lt;conflicted_files&gt;&quot;, then run &quot;git rebase --continue&quot;.<br>hint: You can instead skip this commit: run &quot;git rebase --skip&quot;.<br>hint: To abort and get back to the state before &quot;git rebase&quot;, run &quot;git rebase --abort&quot;.<br>hint: Disable this message with &quot;git config advice.mergeConflict false&quot;<br>Could not apply e71129b... Merge conflicts</pre><p>Then, your IDE will show where did the conflict occurs. Go to that line and see what change is needed. Whether is it your change, or is it the current one or both changes are needed. Do the required change. This is called <strong>resolving </strong>merge conflicts.</p><p>Once you resolve all the conflict, you need to stage, commit these changes and push them again. You can write a new commit message or keep the same message you used earlier.</p><pre>$ git push<br># Now, you will see a message saying you cannot push changes.<br># You need to force push changes in this case<br><br>$ git push --force<br># This will push your changes to the remote</pre><p><strong>What is actually going on?</strong></p><p>This was the breakthrough that made rebasing click for me.</p><p><strong>The Simple Explanation:</strong></p><p>When you rebase your branch onto the latest main, Git does this:</p><ol><li>Takes the head of main branch and makes it the new base of your branch</li><li><strong>Replays</strong> your commits one by one on top of this new base</li><li>Creates <strong>brand new commits</strong> with new commit IDs (even though the code changes are the same)</li></ol><p>That’s why your previous commits are “re-written” — they’re literally new commits now.</p><p><strong>Visually:</strong></p><pre>Before rebase:<br>      C --- D (your feature branch)<br>     /<br>A --- B --- E --- F (main branch, updated by colleagues)<br><br>After rebase:<br>A --- B --- E --- F --- C&#39; --- D&#39; (your feature branch)<br>                (main)<br><br>C&#39; and D&#39; are NEW commits with different IDs than C and D</pre><p><strong>Why this matters:</strong> Your remote feature branch still has the old commits (C and D). Your local branch now has new commits (C’ and D’). They’ve <strong>diverged</strong>. That’s why Git requires git push --force — you&#39;re replacing the old history with new history.</p><p>Now, there are scenarios where you have multiple conflicts in multiple commits. Don’t be afraid. Just repeat the steps. Resolve conflicts in each commit step by step. Once you learn to do this correctly, it becomes simple.</p><p>Imagine you have an e-commerce application. Conflicts occurred in a calculation line, you and a colleague called two different methods to a value in the same line.</p><pre>// Conflict in calculation.js<br>&lt;&lt;&lt;&lt;&lt;&lt;&lt; HEAD (main branch - your colleague&#39;s change)<br>const total = calculateTaxIncluded(subtotal);<br>=======<br>const total = applyDiscountFirst(subtotal);<br>&gt;&gt;&gt;&gt;&gt;&gt;&gt; Your commit message</pre><p>In that situation, you need to understand what should come first.</p><p><strong>What’s the conflict?</strong></p><ul><li>Your colleague’s code: Calculate tax first, then apply discount</li><li>Your code: Apply discount first, then calculate tax</li></ul><p><strong>How to resolve:</strong> You need to <strong>understand the business logic</strong>. Which should come first?</p><ul><li>E-commerce rule: Discounts typically apply to pre-tax amounts</li><li>Correct order: Apply discount → then calculate tax</li></ul><pre>// Resolved:<br>const discounted = applyDiscount(subtotal);<br>const total = calculateTax(discounted);</pre><p><strong>The key insight:</strong> You’re not just picking “my code” or “their code.” You’re <strong>combining both changes</strong> intelligently based on what the code should actually do.</p><h4>git log — View History</h4><p>This is to view the git history of your branch. This is a “nice to have” command when you troubleshoot or try to find when a bug introduced.</p><pre>$ git log <br># This will show history of the branch with commit hash, commit message, person<br><br>$ git log --oneline<br># This is a more clearner way of viewing the git history<br># commit hash, remote branch, local branch, commit message</pre><h4>git cherry-pick — Grab Specific Commits</h4><p>This is used for copying a commit from one branch to another. Translation? Commits are snapshots right? Copying a commit means bringing that snapshot to your current branch and merge changes with the current branch.</p><pre># You are on main, but you need that one bug fix from feature-branch:<br><br># feature-branch:  A --- B --- C --- D (D is the bug fix you need)<br># main:            A --- B --- E --- F</pre><pre>$ git checkout main<br>$ git cherry-pick &lt;commit-hash-of-D&gt;<br><br># Result:<br># feature-branch:  A --- B --- C --- D<br># main:            A --- B --- E --- F --- D&#39;</pre><p>When do I use it</p><ul><li>I accidentally committed to the wrong branch.</li><li>A critical bug fix was made on a feature branch, but I need it on main NOW.</li><li>I need one specific commit from a colleague’s unfinished branch.</li></ul><p>How to find the specific commit:</p><pre>$ git log --oneline<br>a1b2c3d (HEAD -&gt; feature) Fix critical login bug  # ← I want this one<br>e4f5g6h Add new dashboard<br>i7j8k9l Update dependencies<br><br>$ git switch main<br>$ git cherry-pick a1b2c3d</pre><h4>Bonus Commands</h4><p><strong>git stash — Temporarily save work</strong></p><pre>$ git stash              # Save changes and clean working directory<br>$ git checkout main        # Do something else<br>$ git checkout feature<br>$ git stash apply          # Restore saved changes</pre><p><strong>git diff — See what changed:</strong></p><pre>$ git diff               # See unstaged changes<br>$ git diff --staged      # See staged changes<br>$ git diff main..feature # Compare two branches</pre><p><strong>git reset — Undo things:</strong></p><pre>$ git reset HEAD~1       # Undo last commit, keep changes<br>$ git reset --hard HEAD~1  # Undo last commit, DELETE changes (dangerous!)</pre><p><strong>git fetch — Update remote tracking branches without merging:</strong></p><pre>$ git fetch origin       # Download latest from remote, don&#39;t merge<br>$ git status            # Now you can see &quot;Your branch is behind...&quot;</pre><h3>The Workflow in Practice:</h3><p><strong>Morning: Get the latest changes</strong></p><pre>$ git pull origin main<br># Downloads commits from remote and merges them</pre><p><strong>During the day: Work locally</strong></p><pre>$ git add file.js<br>$ git commit -m &quot;Added new feature&quot;<br># Everything happens locally, nothing touches the remote</pre><p><strong>End of day: Share your work</strong></p><pre>$ git push origin feature-branch<br># Uploads your local commits to the remote</pre><h3>Resources That Helped Me</h3><h4>Visual Studio Code</h4><p>Visual Studio Code is the IDE I usually work with. It has some in-built functionalities (Source Control section) and several extensions such as Git Extension Pack, Git History to handle git operations smoothly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rB0ZwSZtPumbM-MYTbNvrA.png" /></figure><p>When you click on the current branch name, you will see options such as create new branch, create new branch from and all the available local and remote branches list.</p><p>To clone, push, pull changes from VS Code, you need to sign into github/gitlab from VS Code. Then you can stage changes, type a commit message and push instantly. Also, you can view changes in each file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/872/1*zeEg6vis-wHEN78JBkwjng.png" /></figure><p>The same features are available in other IDEs such as Antigravity, IntelliJ, Visual Studio and etc.</p><h4>Git GUI</h4><p>When you install Git, the Git GUI also becomes available. When you go the project directory of your computer, you can right click and select “Open Git GUI here” option. Then, the GUI will be opened.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tOe2gGTqIaOgLzDXlK3g7g.png" /></figure><p>The rest is similar to VS Code. You can stage, unstage changes, type a commit message, commit and push changes.</p><h3>From Git Disaster to Git Pro: What Changed</h3><p>Few years back, QA team got a delayed release because I was too scared force push changes. Today, I rebase confidently and actually understand what I’m doing.</p><ul><li><strong>Commits are snapshots, not diffs.</strong> This made branching, merging, and Git’s speed finally make sense.</li><li><strong>Branches are just pointers.</strong> This explained why operations were so fast and why rebasing rewrites history.</li><li><strong>When force-push is safe vs. dangerous.</strong> It’s not evil — it’s necessary after rebasing YOUR feature branch.</li></ul><p>The commands I use daily fit on one hand: git status, git add, git commit, git push, git rebase. That’s it.</p><p><strong>My advice to anyone struggling with Git: </strong>Stop trying to memorize commands. Understand why Git works the way it does. Once the mental models click, the commands become obvious.</p><p>And remember: every senior developer you admire has made Git mistakes. That day I froze in fear? It taught me more than any tutorial ever could.</p><p><strong>You’re not behind. You’re learning.</strong> And that’s exactly where you should be.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2f8a36110ac1" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>