<?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 Sagar Yadav on Medium]]></title>
        <description><![CDATA[Stories by Sagar Yadav on Medium]]></description>
        <link>https://medium.com/@sagar_origin?source=rss-5aeb738f204c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*aIaczeabmT7q71T9.</url>
            <title>Stories by Sagar Yadav on Medium</title>
            <link>https://medium.com/@sagar_origin?source=rss-5aeb738f204c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 15:36:03 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sagar_origin/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[Basics of gits and github: learning blog]]></title>
            <link>https://medium.com/@sagar_origin/basics-of-gits-and-github-learning-blog-42dbc2d50d4f?source=rss-5aeb738f204c------2</link>
            <guid isPermaLink="false">https://medium.com/p/42dbc2d50d4f</guid>
            <category><![CDATA[git-basics]]></category>
            <category><![CDATA[git-beginner]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[git]]></category>
            <dc:creator><![CDATA[Sagar Yadav]]></dc:creator>
            <pubDate>Wed, 01 Jul 2020 15:40:06 GMT</pubDate>
            <atom:updated>2020-07-01T15:43:12.185Z</atom:updated>
            <content:encoded><![CDATA[<p><strong><em>DO YOU GIT ME!!</em></strong></p><p><strong>What is git:</strong></p><p>Git is a decentralised versioning software that helps multiple users to save versions of their work as well as share their work versions with other developers.</p><p><strong>Why git?</strong></p><p>Now I know, one could do all versioning by making multiple copies of files and folders.</p><p>However, at some point one has to become professional and collaborate efficiently in teams. Git is a good tool for a collaborative development team, and once you get used to it, you will appreciate how easy it makes work, as is the case happening with me.</p><p><strong>So what kind of projects can I collaborate in Git?</strong></p><p>Mostly coding work. But it doesn’t necessarily always have to be coding work, one could collaborate almost any file that can be opened in line by line format based work via git. For example, one could write an article with a team via git.</p><p><strong>Let’s start GITTING then :)</strong></p><p>[in case you are wondering.. yeah! That’s my contribution to the English dictionary, Gitting!]</p><p>In Git, one needs a project, which is a repository (folder) either in your local computer or github.</p><p>If it’s the original project then you are the owner of the repository. If you want to work on someone else’s repository and modify it, and then make it better and submit it back to the original repository, you are a forker. [another new word I added to english dictionary, I am forking the English language here :)]</p><p>Always first you need a subject to be tracked, in case of a developer one needs to track file changes across multiple files. In git, there is an area called Stage, where the files are called to be committed.</p><p>Analogy yeah!: You can think of the stage as a marriage stage where people are called for being photographed.</p><p>As in a photograph, the current situation of people on a stage is captured, by commit in Git, we take a snapshot of the current situation in the files on Git Stage.</p><p>And then there is a photo album. Yeah!!</p><p>So in Git we have a log file, which keeps track of all the commits.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hZ6vxTVKRXJ_BcrsUJ8iyw.png" /><figcaption>GIT-STAGE: COMMIT IT = PHOTOGRAPH IT</figcaption></figure><p>Like one opens a photo album and understands the whole celebration via photographs, one can open the log file and check commits (and comments on commits) and understand the whole process of development of the project.</p><p>Are you following me, because I am getting carried away here…</p><p>If you are game then I have no shame, we are friends… right..??</p><p>And for tracking one needs to add the subjects (files and sub-directories /sub-folders) to the staging area and commit (/ take a snapshot). Because our photographer in Git doesn’t photograph anything that is not on stage.</p><p>Now every album at least starts from something, every story starts from somewhere. Once your marriage function starts, get the first photo in so that people can track changes on stage via a vis first photo.</p><p>So always, first a file or group of files need to be committed first for git to start tracking the changes, this is called Git Initial Commit.</p><p>To add a file to the Git stage, we need to use the command:</p><pre>git add &lt;file&gt;</pre><p>Where &lt;file&gt; is the name of our file.</p><p>Now just to know the initial form of the file, we will say / give command:</p><pre>git commit &lt;file&gt;</pre><p>One can think of commit as a snapshot. All changes are tracked from one snapshot to another, which means one commit to another.</p><p>For example, let’s say someone is taking a job interview. And there is a third party recording the interview. The candidate is asked for their name.</p><p>Interviewer: What is your name?</p><p>Candidate: Sagar</p><p>Now in the above conversation, one can write the name of the candidate as Sagar. That will be a snapshot of the person. However, there is no point in tracking / taking a snapshot of everything. Like when the interviewer says: ‘What is your name?’ If we take a snapshot of the conversation at the point where the word ‘What’ was uttered, it is a meaningless snapshot that doesn’t give a meaningful story of the process.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/641/1*Sci0lEEdFA1qHw2GWKF_ZQ.jpeg" /><figcaption>Commits should be meaningful and tell a easily understandable story</figcaption></figure><p>In a meaningful Snapshot, the story is made like this. The person going through the snapshot/ commits will understand the first thing that happened is: the interviewer asked what is your name?</p><p>In the unmeaningful Snapshot, the story is made like this. The person going through the commits will understand that first the interviewer asked “What”, then in the next step the interviewer asked “is”, then in the next step the interviewer asked “your”, then in the next step the interviewer asked “name?”.</p><p>To start the story, one needs an initial commit, but thereafter only meaningful developments should be added to the commit / snapshot.</p><p>Now, the tool that’s most popular to run git commands is a linux-flavoured terminal called gitbash. One should install it and the tool is useful beyond just git, but here we will look more into the git interaction via gitbash terminal.</p><p>So let’s create a file now. To create a file via GitBash, one uses the command:</p><pre>Touch &lt;file&gt;</pre><p>So we create 2 files now, about.html and content.html, we would do so by typing the commands:</p><pre>touch about.html</pre><pre>touch content.html</pre><p>There are no changes being tracked in the files just created. To check the status of the git, we run the command</p><pre>git status</pre><p>It will give us a message that about.html and content.html are untracked files.</p><p>To track the changes in these files, we need to add them to the stage.</p><p>To add them to the git we can use:</p><pre>Git add about.html</pre><pre>Git add content.html</pre><p>These were only two files so we could add them by typing above command with filenames.</p><p>But let’s say there are thousands of files. So we need quicker methods. There are other commands available. The following command will add all the ‘.html’ files present in the directory to the git staged directory.</p><pre>Git add *.html</pre><p>To add all the files present regardless of extension, one can use the command:</p><pre>Git add .</pre><p>Alternatively, one can also use the command</p><pre>Git add -A</pre><p>Now that we have added the files, we need to do the initial commit to take an initial snapshot vis-a-vis whom the changes can be tracked. To do the commit, one used the command:</p><pre>Git commit -m ‘<em>This is the initial commit</em>’</pre><p>With the above command, a snapshot will be taken of all the files which are on stage. And -m ‘MESSAGE HERE’ will help us in telling the story of the commit, as to why we choose to commit there. In the above interview for example, we made a meaningful commitment after candidate introduction, so we can type in the message ‘introduced the candidate’.</p><p>Whatever we type in the message is for understanding the story behind the change we made for deciding to take the snapshot (making commit) and is not changing anything within the files.</p><p>In case we want to revert the files back to the last commit /snapshot anytime, we can use the command:</p><pre>Git checkout &lt;file&gt;</pre><p>In order to revert all the files on stage to previous snapshots:</p><pre>Git checkout .</pre><p>or</p><pre>Git checkout -f</pre><p>When we use -f within a command that means it will ignore the .gitignore file data and force every file to be included in the command.</p><h3><strong>GIT LOG</strong></h3><p>If we want to see the log i.e. a list of all the commits / snapshots taken, use the following command:</p><pre>Git log</pre><p>The log can be very big and in case we are working on a big project, there might be thousands of commits we have made. Now, let’s say we want to view only 2 last commits from the log, we use the command:</p><pre>Git log -p -2</pre><p>In case you want to check 5 logs, the command will be:</p><pre>Git log -p -5</pre><p>After checking the log, you want to get back to typing your commands, for this press q, this will quit you out of log diff and take you back to gitbash command line.</p><p>So I hope that it is a bit clear right now that in local git directory there are at least following areas:</p><p>UnStaged area: or area outside the tracking</p><p>A Staged area: or area where changes are tracked</p><p>A logged area: or area where all the commits / snapshots are submitted.</p><p>Let’s say we want to know the changes in the stage area vis-a-vis last commit or in other words uncommitted changes. For this we use the following command:</p><pre>Git diff — staged</pre><p>If you use the command:</p><pre>Git diff</pre><p>Then it compares the Working Tree vis-a-vis Staging Area.</p><p>To skip the staging area and directly commit changes:</p><pre>Git commit -a -m ‘Your Comment Here’</pre><p>To skip the staging area is not recommended by experts and it is a good practise to first stage and then work upon the file and then commit.</p><pre>Git rm</pre><p><strong>Will delete the file altogether</strong></p><p>If we want to <strong>remove the file only from stage</strong> i.e. we want to untrack it, we use</p><pre>Git rm -cached &lt;file&gt;</pre><p>Command:</p><pre>ls</pre><p>Gives us a list of files in the directory. This is the same as in the linux system.</p><p><strong>While the following command is used to check status:</strong></p><pre>Git status</pre><p><strong>If you want the status to be concise, you can use the command:</strong></p><pre>Git status -s</pre><p><strong>What is .gitignore file?</strong></p><p>We create a file named .gitignore to include name of those files inside this file which need not be tracked, i.e. they will be totally ignored no matter what commands we put, even if we put command to affect all files, these filenames inside .gitignore will be ignore.</p><p><strong>To make a new file one uses the command:</strong></p><pre>Touch &lt;file&gt;</pre><p><strong>To make a folder or directory, one uses the command</strong></p><pre>Mkdir &lt;folder&gt;</pre><p><strong>To remove a folder or directory</strong></p><pre>Rmdir Foldername</pre><p><strong>To remove a file:</strong></p><pre>Rm filename.ext</pre><p><strong>To go inside a child directory:</strong></p><pre>Cd Directory</pre><p><strong>To go inside the parent directory in the directory chain:</strong></p><pre>Cd ..</pre><p>If inside .gitignore file I write a filename or folder name, it will be ignored by all the commit or staging commands i.e. it will not be tracked.</p><p>If we want that all the <strong>files with a particular extension get ignored</strong>:</p><pre>*.ext</pre><p>Where .ext is the extension name.</p><p>If I want to <strong>ignore a whole folder</strong> then I will write</p><pre>&lt;folder&gt;/</pre><p>Where I write / after the folder name. / tells .gitignore that this is the name of a folder.</p><p>If we only want to <strong>ignore files which are inside the folder where .gitignore is</strong>, then we can add / before the ignore definition. For example:</p><pre>/&lt;file&gt;</pre><p>This will only ignore this filename inside the same folder where .ignore is. However if there is anything in any other directory including child directories, those files will not be ignored.</p><h3><strong>BRANCHES</strong></h3><p><strong>What are the branches?</strong></p><p>If we run a git status, we will come to know that we are in the main branch.</p><p>Let’s say our company has a running website and the business of the company is dependent upon it. So what happens is, when we edit the code of the website and the website breaks as a result, this is very unprofessional upon our part as well as a loss for the company.</p><p>For situations like there, we have a solution called branches.</p><p>Branch is a copy of the original master branch, where you can work and edit your code without affecting your master branch (or in the above example, without affecting the live website).</p><p><strong>To check out if you are on master branch</strong> or some other branch, simple type:</p><pre>Git branch</pre><p><strong>To create a new branch</strong> named NewBranch from the master branch, simply type:</p><pre>Git branch NewBranch</pre><p>After creating the branch NewBranch, we may want to go to the new branch to work on the website code. So <strong>to switch to the branch</strong> we just need to type:</p><pre>Git checkout NewBranch</pre><p>Once we are done working with the copy of the website on NewBranch and tested it to see that it works properly, then we can <strong>merge it into the master branch</strong>, to add the changes to the master branch. We type:</p><pre>Git merge NewBranch</pre><p>The above command will merge NewBranch into master branch.</p><p>With this, all the commits of NewBranch have now also gone to master branch.</p><p>Remember that before merging a branch into the master branch, we need to <strong>go into the master branch</strong> with:</p><pre>Git checkout master</pre><p>Then we <strong>merge the NewBranch</strong> in it by typing:</p><pre>Git merge NewBranch</pre><p>As we know, we can <strong>create a NewBranch</strong> by the following command:</p><pre>Git branch NewBranch</pre><p>Then we <strong>switch to NewBranch</strong> by typing:</p><pre>Git checkout NewBranch</pre><p>However, if we want to let’s say create NewBranch2 and we want to switch to it immediately then there is no need to write two commands, we can <strong>make the NewBranch2 as well as switch to it via a single command:</strong></p><pre>Git checkout -b NewBranch2</pre><p><strong>To delete a branch:</strong></p><pre>Git branch -D NewBranch2</pre><p><strong>To upload or upstream to github:</strong></p><p>We first create a github account and then make a repository.</p><p>After creating the repository we get a URL to the repository. Let’s say the url is <a href="https://github.com/sagarishere/firstTask">https://github.com/sagarishere/firstTask</a></p><pre>git remote add origin <a href="https://github.com/sagarishere/firstTask.git">https://github.com/sagarishere/firstTask.git</a></pre><p>Here we are <strong>giving the name “origin” to the url</strong> <a href="https://github.com/sagarishere/firstTask.git">https://github.com/sagarishere/firstTask.git</a></p><p>Now we can later on call that url and push / upstream material to it with the word origin.</p><p>To <strong>find out the remotes on the url or github repo</strong>, type:</p><pre>Git remote</pre><p>The above should give us the output:</p><pre>origin</pre><p>As origin is the only remote it is connected to at the moment, origin being the name we gave to github repo link.</p><p>To <strong>find out the urls that origin will push or pull/fetch from at github</strong>, type:</p><pre>Git remote -v</pre><p>This should give us the result</p><p>origin <a href="https://github.com/sagarishere/firstTask.git">https://github.com/sagarishere/firstTask.git</a> (fetch)</p><p>origin <a href="https://github.com/sagarishere/firstTask.git">https://github.com/sagarishere/firstTask.git</a> (push)</p><p>So to <strong>push the master branch from our local computer to github</strong>, we give the command:</p><pre>Git push origin master</pre><p>Where origin is the url of the github, instead of url we can use the word origin or whatever name we gave to the url while using command git remote add origin <em>url</em></p><p>The command:</p><pre>Git push -u origin master</pre><p>Will push all the changes we committed in our master branch at local computer to our target repo on github.</p><p>If you don’t have access to the repo at github as it is in private mode, you could go to the settings and then take SSH and GPG Keys.</p><p>If you use</p><pre>Git push -u origin master</pre><p>Next time when you give command git push it will automatically repeat the last push command we used with -u, which is to say command:</p><pre>Git push</pre><p>will repeat:</p><pre>Git push -u origin master</pre><h3><strong>CLONE</strong></h3><p><strong>To clone a git repo from github to your local repository on computer</strong>, type:</p><pre>Git clone <a href="https://github.com/sagarishere/firstTask.git">https://github.com/sagarishere/firstTask.git</a> &lt;folder&gt;</pre><p>The above git will be cloned from github to the folder named &lt;folder&gt;</p><p>Cloning a repo is done to study the code of a github repo on a local computer.</p><p>If we don’t specify the name of the folder in which git has to be cloned, then the command will create a Folder within the working directory with the name of the github repository.</p><p>For example, if we type:</p><pre>Git clone <a href="https://github.com/sagarishere/firstTask.git">https://github.com/sagarishere/firstTask.git</a></pre><p>Then a new folder will be created on our local computer named firstTask and inside it the git will be cloned.</p><p><strong>For a successful developer career, remember the below quote:</strong></p><p>For instagram generation: If it’s not on photo, it didn’t happen. And your friends are not jealous of you.</p><p>For modern developers: If it’s not in the commit, you didn’t code. And your friends are… what friends, you are a developer, remember?</p><p>I feel nice that you are reading till here… I will invite you to my marriage now if I get married again. For the time being, as I used marriage analogy for a Git, let’s connect over github:</p><p>My github link is: <a href="https://github.com/sagarishere">https://github.com/sagarishere</a></p><blockquote>And this is my mentor: <a href="https://github.com/elemson">https://github.com/elemson</a> (all this blah blah is my own, all the technical knowhow I got from him and other developers at juststart.dev)</blockquote><p>Note:The above post was developed as part of my learning process, where I have made an effort to highlight my learnings about GIT at <strong>juststart.dev</strong></p><p>Edit: the post is still under active editing and I hope to improve the storyline and add images for illustration.</p><p>Love you all and stay tuned,</p><p><em>Sagar</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=42dbc2d50d4f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>