<?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 Shan Ganegoda on Medium]]></title>
        <description><![CDATA[Stories by Shan Ganegoda on Medium]]></description>
        <link>https://medium.com/@shanganegoda96?source=rss-491432f49b4a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*KvHtk5DSflMdvI_s</url>
            <title>Stories by Shan Ganegoda on Medium</title>
            <link>https://medium.com/@shanganegoda96?source=rss-491432f49b4a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 23:51:12 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@shanganegoda96/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[Understanding the basics of Git Workflow]]></title>
            <link>https://medium.com/@shanganegoda96/understanding-the-basics-of-git-workflow-9fd77833202a?source=rss-491432f49b4a------2</link>
            <guid isPermaLink="false">https://medium.com/p/9fd77833202a</guid>
            <dc:creator><![CDATA[Shan Ganegoda]]></dc:creator>
            <pubDate>Fri, 16 Feb 2024 08:24:46 GMT</pubDate>
            <atom:updated>2024-02-16T08:24:46.681Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cASq9GdnFz2SdmWHx3gOwg.jpeg" /></figure><p>Working with git can be intimidating sometimes, because it’s easy to make mistakes that would mess up your repository. I believe that it is mainly because we do not really know what’s happening to our files under the hood even with basic git commands. Hence, when working with version controlling it is crucial to understand the different places where code can live. Why?</p><ul><li>Effective collaboration with other developers.</li><li>Understand why certain errors occur, and why git sometimes doesn’t behave as you expect to.</li><li>Better grasp branching and merging strategies/concepts.</li><li>Better conflict resolution.</li></ul><p>A common misconception is that code can live only in two locations either in our local machine or on a remote server (github/bitbucket).</p><p>But in reality code can live in four locations.</p><ul><li>Working directory (also called the “Local Workspace”)</li><li>Staging Area (also called the “index”)</li><li>Local Repository</li><li>Remote Repository (eg. — GitHub , Bitbucket)</li></ul><p>Now let’s have a look at some basic git commands we use daily and understand how code travels between these four locations (workflow).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*pr1EJh6HilZTguFfoCiAAA.png" /></figure><ol><li><strong><em>clone :</em></strong> We usually perform this step, when we need to copy the contents of an existing repository onto our local machine (local repository and the working directory). If we are creating our own repository, this step is irrelevant.</li></ol><pre>git clone &lt;remote_url&gt;</pre><p>2. Pushing your local changes to the remote repository is broken down into 3 steps.</p><p><strong><em>add :</em></strong> The add command, adds a file(s) to the staging area. Which basically means that, it is marked <strong>to be</strong> committed.</p><pre>git add &lt;file_name&gt;</pre><p>Why do we need a staging area?<br>It gives you flexibility and control over the changes you want to include in your next commit. In an IDE like VS Code, you can see your staged files and the changes in code that you have made in each file, clearly. Commits in git should be done thoughtfully and with caution, hence it is a good practise to always review your staged changes before committing.</p><p><strong><em>commit </em></strong>: After staging the changes, the commit command, adds the staged changes to your local repository (<em>see figure above</em>).</p><pre>git commit -m &lt;&quot;commit_message&quot;&gt;</pre><p><strong><em>push</em></strong> : As the name suggests it pushes the code to the remote repository. <em>(see figure above)</em>. At this point all the changes you have made to the codebase will be visible and accessible to anyone who has access to the remote repository.</p><pre>git push</pre><p>3. Generally, when you are working with other developers on a project, you will regularly need to take in the changes done by others, to your local repository and to your working directory.</p><p>The “pull” command, directly updates your local repository and your working directory with the latest changes in the remote repository, in one go. It is a combination of “fetch” and “merge” which we will dive into next.</p><pre>git pull</pre><p>4. “Fetch” and “merge” is an alternative to the “pull”. The “fetch” command updates <strong>only </strong>your local repository with the latest changes (<em>see figure above</em>). The “merge” command updates your working directory as a next step.</p><pre>git fetch<br>git merge</pre><p>Let’s see how this can be useful instead of “pull”.</p><p>On some occasions, you’ll need to compare the incoming changes from the remote repository before updating your working directory. “Fetch” allows this. Once fetched and the local repository is updated, we can use the command <em>“git diff HEAD” </em>to compare incoming changes. In other words, it shows the difference between your <strong>updated local repository</strong> and your <strong>working directory</strong>.</p><p>Once you compare the difference you can either decide to merge the changes or you can make necessary changes to your working directory and stage them to avoid possible merge conflicts.</p><p>When you’re working on a real world project with other developers, it is usually not as straightforward as described above. You may run into many unexpected behaviors in your workflow. Understanding from where to where code actually travels will help you dissect these problems more efficiently.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9fd77833202a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>