<?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[Sawani Soman - Medium]]></title>
        <description><![CDATA[DevOps Engineer in Bay Area - Medium]]></description>
        <link>https://medium.com/sawani-soman?source=rss----973abb871695---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Sawani Soman - Medium</title>
            <link>https://medium.com/sawani-soman?source=rss----973abb871695---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 19:43:48 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/sawani-soman" 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 and Github]]></title>
            <link>https://medium.com/sawani-soman/git-and-github-23e0fc498c65?source=rss----973abb871695---4</link>
            <guid isPermaLink="false">https://medium.com/p/23e0fc498c65</guid>
            <dc:creator><![CDATA[Sawani Soman]]></dc:creator>
            <pubDate>Tue, 21 Apr 2020 16:48:38 GMT</pubDate>
            <atom:updated>2020-04-21T16:48:38.751Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vsLM0sSeDhyK_klpAkSSLw.gif" /></figure><p><strong>Pre-requisites:</strong></p><blockquote><a href="https://git-scm.com/book/en/v2/Getting-Started-Installing-Git">Git installed</a> on your computer and <a href="https://help.github.com/en/github/getting-started-with-github/signing-up-for-a-new-github-account">Github account</a> with basic understanding on <a href="https://guides.github.com/introduction/git-handbook/">what is GIT and GITHUB</a>.</blockquote><blockquote><a href="https://www.redhat.com/sysadmin/basic-linux-commands">Basic Linux commands knowledge</a></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/598/1*zYZUthHAr0zB8jUll9q-_w.png" /></figure><p><strong><em>Basic GIT Workflow:</em></strong></p><p>I’ve created a GIT Workflow to understand how basic GIT commands works.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BMloUCcbFuIi31zqCyi7ag.gif" /><figcaption>Basic GIT Workflow</figcaption></figure><p><strong><em>Workspace area:</em></strong></p><p>In this space user creates new files and modifies existing files. Changes are tracked by GIT.</p><p><strong><em>Staging Area</em></strong></p><p>All the modified files which are required to be committed are found at this place.</p><p><strong><em>Check git version:</em></strong></p><p>Check if git is installed successfully using this command.</p><pre>$ git --version</pre><p><strong><em>Configure GIT:</em></strong></p><pre>$ git config --global user.name &quot;username&quot;<br>$ git config --global user.email &quot;email&quot;</pre><p><strong><em>Create a new project folder:</em></strong></p><p>Create a new repository, go inside it and create a new file.</p><pre>$ mkdir your_repo<br>$ cd your_repo<br>$vi index.html</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e2862dfe4343ad95f3cd945d4a9fc04c/href">https://medium.com/media/e2862dfe4343ad95f3cd945d4a9fc04c/href</a></iframe><p>I’ve created a simple HTML file and contents are as shown above. You can create any file.</p><p><strong><em>Initialize:</em></strong></p><p>Inside your project folder initialize the repository as git by performing below command.</p><pre>$ git init</pre><pre>Initialized empty Git repository in /Users/sawanisoman/Desktop/git_blog/.git/</pre><p><strong><em>Git add command:</em></strong></p><pre>$ git add index.html</pre><pre>Or</pre><pre>$ git add .</pre><p>Command will add example.html file from the working directory to the staging area. Dot “.” indicates all files in the repository.</p><pre>$ git status</pre><pre>On branch master</pre><pre>No commits yet</pre><pre>Changes to be committed:<br>  (use &quot;git rm --cached &lt;file&gt;...&quot; to unstage)</pre><pre><strong>new file:   index.html</strong></pre><p>It will show the files which are added to the staging area and waiting for commit. All staged files are shown in green and unstaged files are shown in red. [Note: Please check this after performing command on your computer]</p><p><strong><em>Git commit command:</em></strong></p><pre>$ git commit -m “message”</pre><pre>[master (root-commit) 71cb6d8] first commit<br> 1 file changed, 12 insertions(+)<br> create mode 100644 index.html</pre><p>All the files in the staging area are committed to the local repository. Changes are not yet pushed to the remote repository.</p><p><strong><em>Check logs:</em></strong></p><p>After you commit files, if you check the log, you will see commit Id is created, which is 40 character hash with commit message and author details. This command shows commit history.</p><p>HEAD signifies the most recent commit.</p><pre>$ git log</pre><p><a href="https://help.github.com/en/github/getting-started-with-github/create-a-repo"><strong><em>Create a repository on Github</em></strong></a><strong><em>:</em></strong></p><p>For simplicity, I’ve not created a readme file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*my8N_fJ6PqKOUgazaD2iqA.png" /></figure><p><strong><em>Add remote URL: On your local computer</em></strong></p><pre>$ git remote add origin <a href="https://github.com/sawani02/git_blog.git">https://github.com/sawani02/git_blog.git</a></pre><p><strong><em>Replace your GitHub repo URL which you will find after creating a repository on Github.</em></strong></p><p>In the above command, the “<strong>origin</strong>” is set as a new remote. There is no need to mention the Github URL after setting the remote name “origin”. You can use any remote name instead of origin.</p><p><strong><em>Verify the new remote:</em></strong></p><p>It provides a list of remotes. I will explain git fetch later.</p><pre>$ git remote -v</pre><pre>original <a href="https://github.com/sawani02/git_blog.git">https://github.com/sawani02/git_blog.git</a> (fetch)<br>original <a href="https://github.com/sawani02/git_blog.git">https://github.com/sawani02/git_blog.git</a> (push)</pre><p><strong><em>Git push command:</em></strong></p><p>Pushes changes from local to remote repository. You will be prompted to provide your username and password of Github.</p><pre>$ git push -u origin master</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/986/1*9biT2OsQeAaBLNvle32wOg.png" /></figure><p>Check your Github repository to confirm if files are pushed to the remote repository by refreshing Github.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kTzEzvqfsrOkZc4MVWC7lw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/664/1*qr1X4PvXZvK4vv8JrWqY2w.png" /></figure><p><strong><em>Scenario 1:</em></strong></p><p>Let’s say you are Developer Y and Developer X (from the same organization) has already created a repository on Github with some source code. Now, you want to work on a new feature. [Check GIT Workflow diagram to understand scenario]. The new feature will be developed by creating a new branch.</p><p>Let’s say I’m Developer X and this is my Github repo: <a href="https://github.com/sawani02/branch-practice/tree/master">https://github.com/sawani02/branch-practice/tree/master</a></p><p><strong><em>Fork:</em></strong></p><p>On the right-hand side, click on the fork option. This option will copy repository and you can experiment with it, without affecting the original project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qkePAFGonzUEc8CtJuu4ww.png" /></figure><p><strong><em>Git clone command:</em></strong></p><p>This command will help to get a copy of the remote repository in your local. Copy the Github URL (marked in red) from the Github repository and paste it in the below command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vINwsHXijyKFYFX3ce_FtQ.png" /></figure><pre>$ git clone github_url<br>$ cd github_repo</pre><p>In the above example, Github repo name is branch-practice.</p><p><strong><em>Git Fetch</em></strong></p><p>If changes have been made to remote repository on Github and you just want to see those changes without copying the files into your workspace, use git fetch command.</p><pre>$ git fetch</pre><p><strong><em>Git Pull</em></strong></p><p>Like fetch it will show the changes from Github to local repo. It will also merge changes to the working directory. You will have an update copy of the remote repository.</p><p><strong><em>Branching:</em></strong></p><p>Below command will list all the branches. Until now we were only working with one branch which is a master by default.</p><pre>$ git branch</pre><pre>* master</pre><pre>$ ls</pre><p>Asterisk “*” represents the current branch.</p><p>To create a new branch type below command. Give any name for the branch that is relevant to your project.</p><pre>$ git branch your_branch_name</pre><p>Branch is created so that the work done by another developer in the Master branch is not affected.</p><p><strong><em>Git checkout command:</em></strong></p><p>Git checkout is used to change the branch from master to other branches or vice versa. <strong><em>The new branch will have a copy of all the files committed in master branch until now.</em></strong></p><pre>$ git checkout your_branch_name</pre><pre>Switched to branch &#39;feature&#39;</pre><p>Note: “feature” is my branch name.</p><p>Now you can start working on your branch.</p><p><strong><em>Create any new file, perform git add ., git commit commands. If you perform git log command, you can see the commit history [as shown in below screenshot]</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LVpql8hOhIIM7pABQa2V6g.png" /><figcaption>Branching</figcaption></figure><p><strong><em>HEAD: It is a pointer that points to last commit id of master.</em></strong></p><p><strong><em>Push the code to your branch:</em></strong></p><p>On <strong>Github repository,</strong> there is currently only one branch which is master. Using the below command we will push the branch and its contents to Github.</p><pre>$ git push -u origin your_branch_name</pre><p>On Github repository, the new branch will be created with files.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NptiZEXOacPz0pFQ6erNFg.png" /><figcaption>Master branch after branch merging</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*P0wrbuUZI5vhDf-BqVwL9g.png" /></figure><p>After creating a branch and completing the feature development, there are two options either merge to master or rebase. What does this two options exactly do…..?</p><p><strong><em>Scenario 2:</em></strong></p><p>The GIF below demonstrates the scenario, which will help you to understand merge and rebase.</p><p><strong><em>Perform the steps as given below. [Note: you can use same working directory used during basic topics where index.html was committed]</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*M8NAvX2bfQ3X4PMl7sQ1Nw.gif" /><figcaption>Scenario 2</figcaption></figure><p><strong><em>On Master branch:</em></strong></p><ul><li>File index.html is already present in the master branch.</li><li>Create main.py file, add commit to the git and check logs.</li><li>Base corresponds to head.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E1FHPZKAFrkaOWkoNitJrg.png" /></figure><p><strong><em>On Feature branch:</em></strong></p><ul><li>Create a new branch “feature”. Perform git checkout.</li><li>Create a new file feature.py, add commit and check logs.</li><li>Observe the position of the head pointer (base).</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Uz3IhHrdgDdqQHq2qTWIfg.png" /></figure><p><strong><em>Master branch:</em></strong></p><ul><li>Change the branch to master. Create a new file test.js, add, commit and check git logs.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w8qo1in2NjXRMD1p2VrsCQ.png" /></figure><p><strong>This new commit on master is not present in a feature branch. You can see from GIF that in master branch base is pointing to different commit and in feature branch base is pointing to a different commit.</strong></p><p>[Note: Make sure you perform all the above actions mentioned in scenario 2]</p><p><strong><em>Merging:</em></strong></p><p><strong><em>Merge the changes in local [using git command]: For understanding of GIT merge, perform below actions after scenario 2.</em></strong></p><p>First checkout to the master and then tell the git to merge the contents of the branch into master.</p><pre>$ git checkout master<br>$ git merge branch_name</pre><p>After git merge command vi editor will open, write merge commit message.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VIVcAD8j2_mh1PRwb4ytRQ.png" /></figure><p>After merging check the log, you will notice a new commit Id is created.</p><p>Check the head pointer, that is the extra commit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xyuo4Of-_M6ybR3iYyrTug.png" /><figcaption>Merging files and logs</figcaption></figure><p>Push the merged files to GitHub repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RqX54QLU8DGbAga5_6NjUQ.png" /></figure><p>After merging, you can delete the branch as it becomes redundant.</p><pre>$ git branch -d branch_name</pre><p><strong><em>Merge changes in remote directory </em>[Followed in organizations, not required for this tutorial]:</strong></p><p>Once you are done with the development of your branch, there will be a need to merge those changes into master. You can create a pull request on Github which is available next to your branch name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8KbuV8vWEkjTJ-2Q7zHZOw.png" /><figcaption>Creating a pull request to merge the branch</figcaption></figure><p><strong><em>Rebase:</em></strong></p><p>Changing the base of your branch. <strong><em>To understand rebase create a new folder. Perform all the actions mentioned in the scenario 2.</em></strong> Now instead of merging, we will rebase.</p><pre>$ git checkout your_branch_name</pre><pre>$ git rebase master</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*sOQTFe7VNAQrFPLtkSXleg.jpeg" /></figure><p>If you observe Scenario 2 Gif, for feature branch base for master is test.js, however in the master branch, as test.js is created after creating a new branch, this file is not copied to branch and on master this file commit is the new head. To adjust the base of master in feature branch and to avoid extra commit id, rebasing strategy is used.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/704/1*xVTnXPLikPwmh2p1b_1q4w.png" /><figcaption>Commands to create, add and commit files</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*WIaRsQy120hn0COlWiufcw.png" /><figcaption>Rebase logs</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=23e0fc498c65" width="1" height="1" alt=""><hr><p><a href="https://medium.com/sawani-soman/git-and-github-23e0fc498c65">Git and Github</a> was originally published in <a href="https://medium.com/sawani-soman">Sawani Soman</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>