<?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 Amit Prajapati on Medium]]></title>
        <description><![CDATA[Stories by Amit Prajapati on Medium]]></description>
        <link>https://medium.com/@thisAmit?source=rss-e6f25903ed6c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*F3ywriQ5fKUb0e9UfTLFYw.jpeg</url>
            <title>Stories by Amit Prajapati on Medium</title>
            <link>https://medium.com/@thisAmit?source=rss-e6f25903ed6c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 16:59:29 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@thisAmit/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 git hooks in the easiest way]]></title>
            <link>https://codeburst.io/understanding-git-hooks-in-the-easiest-way-bad9afcbb1b3?source=rss-e6f25903ed6c------2</link>
            <guid isPermaLink="false">https://medium.com/p/bad9afcbb1b3</guid>
            <category><![CDATA[github]]></category>
            <category><![CDATA[hooks]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[git-hooks]]></category>
            <category><![CDATA[git]]></category>
            <dc:creator><![CDATA[Amit Prajapati]]></dc:creator>
            <pubDate>Sat, 16 May 2020 05:26:46 GMT</pubDate>
            <atom:updated>2020-07-15T09:25:01.352Z</atom:updated>
            <content:encoded><![CDATA[<h3>Understanding Git Hooks</h3><h4>The easy way to get Git</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*nPmy1R-4tuiAYogkwbNA9A.png" /></figure><p><strong>Hello Folks!</strong></p><p>As promised, I have come up with another article. Here, we will learn about hooks. So, keep up with the article.</p><blockquote>Today’s Inspiration: “Today is a good day to learn something new.”</blockquote><p>“Enforce code quality and increase productivity” <strong>Remember!</strong> If something takes too much time or effort, people will avoid it! So, the solution?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/420/1*ebym7oKt0nMVIXp_nhATVQ.png" /></figure><p>Let’s begin… 🙂</p><p>Today’s top companies give the highest priority to the quality of the code you have written. So, we have a concept of <strong>git hook </strong>which does not allow you to commit in “<em>master branch” </em>unless your code validation is accepted. I think it is helpful to maintain a better quality of code.</p><p>If you’ve ever worked on an open-source project, or you’re working with a team, it’s very likely you’re using some kind of version control. <em>Version Control System (VCS)</em> has become one of the main requirements for any project, Git being the foremost popular one. However, as the team grows in number, it becomes difficult to handle the different code styles and to enforce certain rules across all the contributors. These issues aren’t noticed by a contributor until he has pushed his changes which end in overheads for the core maintenance team. To enforce these rules and validate the code being pushed, Git provides a great feature, called Git <strong><em>Hooks</em></strong>.</p><h4>So what are Git hooks?</h4><p>Git hooks are custom scripts that git executes before or after events such as <em>commit</em>, <em>push</em>. Git hooks are a built-in feature there is no need to download anything. They are unique and run locally and resides inside the <strong>.git/hooks</strong> directory.</p><p>Git hooks can be used to:</p><ul><li>Check commits for <em>errors </em>before they are pushed.</li><li>Ensure code meets project standards.</li><li>Notify team members about changes.</li><li>Push code into a production environment, and more.</li></ul><p>There are two types of hooks:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/1*29ENNb7bzgp1ejPgUNoxGw.jpeg" /></figure><ul><li><strong>Client-Side (Local) Hooks</strong></li><li><strong>Server-Side (Remote) Hooks</strong></li></ul><p><em>Server-Side Hooks</em>, as the name suggests, are installed on the server and are triggered only just in case of network operations. For example — <strong><em>Post-Receive </em></strong>may be a sort of server-side hook triggered after a successful push. This makes it an ideal place to send notifications to all the contributors.</p><p><strong>e.g:</strong> <em>pre-receive, update, post-receive</em></p><ol><li>The pre-receive hook is executed every time somebody uses git push to push commits to the repository.</li><li>The post-receive hook gets called after a successful push operation.</li></ol><p><em>Client-Side</em> Hooks reside on one’s local repository and are executed when a git event is triggered. Here, a git event can commit, push, rebase, etc. When we run certain git commands, git search for the hooks within the git repository to ascertain if there’s an associated script to run. For example, one could have a pre-push hook to validate that the code enforces certain rules before it’s pushed to the remote repository.</p><p><strong>e.g:</strong> <em>pre-commit, prepare-commit-msg, commit-msg, post-commit</em></p><ol><li>The pre-commit script is executed every time you run git commit command.</li><li>The prepare-commit-msg hook is called after the pre-commit hook to populate the text editor with a commit message. This is where auto-generated commit message is created.</li><li>The commit-msg hook is much like the prepare-commit-msg hook, but it is called <strong><em>after </em></strong>the user enters a commit message.</li><li>The post-commit hook is called immediately after the commit-msg hook. This is after a commit has taken place.</li></ol><p>In this image, we have different hooks name with their event (means which command executes which hook).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/783/1*a-kyVc-ZJXK7Trd4kveNhg.png" /></figure><h4>Implementing Git Hooks</h4><p>Git hooks are a built-in feature that comes with every git repository. When initializing a new project git populates the hooks folder with template files.</p><ol><li><strong>Navigate to the hooks directory</strong></li></ol><pre>$ <strong>ls .git/hooks/</strong></pre><p>Notice the files inside, namely:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E-Cfut-6bvuqXCYA6CLJWQ.png" /><figcaption>sample files inside the hooks directory</figcaption></figure><p><strong>2. Install your hook</strong></p><p>To enable the hook scripts, simply remove the <strong>.</strong>sample extension from the file name. Git will automatically execute the scripts based on the naming. For my purpose, I renamed the “<strong>commit-msg.sample</strong>” file to “<strong>commit-msg</strong>”.</p><p><strong>3. Select a language to write your hook script.</strong></p><p>The default script files are written in shell scripts, but you can use any scripting language you are familiar with as long as it can be run an executable. This includes <em>Bash</em>, <em>Python</em>, <em>Ruby</em>, <em>Perl</em>, <em>Rust</em>, <em>Swift, </em>and <em>Go</em>.</p><p>Open up the script file in your code editor and define your language of choice in the first line, using the<strong> shebang (#!)</strong> sign, so git knows how to interpret the subsequent scripts. Note that you need to include the path of your interpreter. For Mac users who wish to write the scripts in Python, for instance, the Apple-provided build of Python is located in /usr/bin. So, the first line would look like:</p><pre>#!/usr/bin python</pre><p>If you want to use Bash, on the other hand, the first line would be:</p><pre>#!/bin/bash</pre><p>And for shell:</p><pre>#!/bin/sh</pre><p><strong>4. Write your script</strong></p><p>From here on, you could write any script and Git will execute it before any commits to this project. For reference, I wrote my script in Bash, and here is what I ended with up.</p><ul><li><strong>commit-msg hook</strong></li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5d60199998df78f23b398c6557e5f5aa/href">https://medium.com/media/5d60199998df78f23b398c6557e5f5aa/href</a></iframe><p>Let’s understand this script:</p><ul><li>Line 3–7 define text-decoration variables, which are used to enhance my console message. For coloring the variables, I have used <a href="https://gist.github.com/vratiu/9780109">Git shell coloring</a>.</li><li>Line 9–10 gets the commit message form the console.</li><li>Line 12–13 defines the <em>REGEX </em>pattern from which the commit message will be validated.</li><li>Line 14–21 is a conditional statement that will check the commit message if it matches with REGEX pattern then successful commit otherwise failed.</li><li>Notice that if the conditional above evaluates to a 1 status, line 19 extends that by exiting with a 1 status to indicate failure. This prevents changes from being commit.</li></ul><p>We have to give executable permission to our script file using the <strong>chmod </strong>command.</p><pre>$ chmod +x .git/hooks/commit-msg</pre><p>After writing your hook scripts, just sit back and watch Git do all the work:</p><p>Let’s see the example below:</p><ol><li>Commit with an improper commit message</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/897/1*QDsydpI6VMFQdY9h9jiB6w.png" /><figcaption>Bad commit</figcaption></figure><p>2. Commit with a proper commit message.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/661/1*ZWCAXNeDXpjxspgDBLIzUA.png" /><figcaption>Good commit</figcaption></figure><p>3. If you want to bypass the commit-msg hook then use <strong>--no-verify</strong> flag.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/805/1*-B80xcJSXrDwpwEdNCdZ2A.png" /><figcaption>Bypass commit</figcaption></figure><ul><li><strong>pre-push hook</strong></li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/07996a3ebd257d3531335015dd9df286/href">https://medium.com/media/07996a3ebd257d3531335015dd9df286/href</a></iframe><p>Let’s understand this script:</p><ul><li>Line 5 determines the current branch with git rev-parse --abbrev-ref HEAD.</li><li>Line 6–10 is a conditional statement, will check in which branch you are in. If you’re in the <em>master </em>branch then the script will not allow you to push code in the master branch. If not in master, then you can push.</li><li>Line 12–16 is also a conditional statement, will check your <em>current branch</em> and also check the <em>date </em>and <em>week</em>. If a week is greater than <strong>5 </strong>means you i.e <em>Saturday </em>and <em>Sunday </em>then the script will not allow you to push the code.</li></ul><p>This <strong>pre-push</strong> script has some advantages as well because in the IT industry who wants to work at the weekend, no one really? So, this hook prevents you to push code on a <em>Friday </em>night because it’s having a high chance to get an error when you pushed the code. So, it prevents that’s awesome!</p><ol><li>Error while pushing to the master branch.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jCe8A23ZrdqQMbRXWjNyPA.png" /></figure><p>2. Successfully pushed to another branch on weekdays except for weekends.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/846/1*SNDzS7ipYvuTx4Qi3FjCEA.png" /></figure><ul><li><strong>pre-commit hook</strong></li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/43d0736f37e0f37a468845d19d9be126/href">https://medium.com/media/43d0736f37e0f37a468845d19d9be126/href</a></iframe><p>While developing any software, at some point the developers have to debug the code to check the bugs or API response. If you are from the JavaScript background then developers mostly use “<strong>console.log()</strong>” statement to print something in console. Consider a scenario, where you have debugged the code and forget to remove those<strong> </strong>“<strong>console.log()</strong>” statements and you’re ready to commit the changes. But, you don’t want those statements to commit. So, in that case, we can take the help of the pre-commit hook in which we have written a script will automatically check the code before commit. If the scripts found any “<strong>console.log()</strong>” statements then it will not allow you to commit. That’s amazing, right?</p><p>Let’s understand the code:</p><p>The script uses the <strong><em>grep </em></strong>command to search for the forbidden strings like “TODO:” and “console.log()” in the staged codebase. If strings are found then abort the commit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uuT-sE7zGzf08Mv3EJvI1g.png" /><figcaption>Commit Rejected</figcaption></figure><p>Now, If we remove those statements commit will be accepted.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/256/1*4L58DpctbURy2E7T9unaig.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/867/1*-JtYZ6WuGlO4y3aEf-ZGUw.png" /><figcaption>Commit Accepted</figcaption></figure><p>Be aware of the --no-verify option to git commit. This bypasses the pre-commit hook when committing.</p><p>If you are a big fan of <em>JavaScript </em>and worrying about your coding styling and error-prone code? Wouldn’t it be nice to have something in place to force people to fix their code before they can even push it? Well good news, <strong><em>Husky </em></strong>is here to help.</p><p><em>Prevents bad commit or push (git hooks, pre-commit/pre-commit, pre-push/pre-push, post-merge/post-merge, and all that stuff…)</em></p><h4>What is Husky?</h4><p>Husky is a very popular (1 million downloads a month) npm package that allows custom scripts to run against your repository. Husky works with any project that uses a package.json file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*ZxoSSCeP5aHIlsmtRuMagg.jpeg" /></figure><h4>Set up</h4><p>Let’s get started by setting up a <em>package.jso</em>n file:</p><p>Firstly, we need to run npm init to initialize the project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*R4i1S1Htf3N8m6irGlW_GA.png" /><figcaption>package.json file creation</figcaption></figure><p>When you run this command it will ask you some questions such as your package_name, version, and entry point (means which file the husky will look at first i.e index.js). After that, it will generate <strong>package.json</strong> file in your directory.</p><p>Let’s view your files.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/995/1*WRmbAvreF343bOGeuO4fhg.png" /><figcaption>Files in my directory</figcaption></figure><p>Now, We’ll be using JSHint as our linter to run before we push or commit our code, this is done via the “<strong>scripts</strong>” section in our package.json file.</p><h4>What is JSHint?</h4><p>JSHint is a community-driven tool that detects errors and potential problems in JavaScript code. Since JSHint is so flexible, you can easily adjust it in the environment you expect your code to execute. JSHint is open source and will always stay this way.</p><p>Before any modifications, we need to install jshint and <a href="https://www.npmjs.com/package/husky">husky</a> package through npm.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EDU54kldxVQaccfb1NbJAg.png" /><figcaption>Installing jshint and husky package</figcaption></figure><p>You can see these dependencies in your “<strong>dependencies</strong>” section in your package.json file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*kdxYNmjk0ey0hAuYp6cKng.png" /><figcaption>dependencies</figcaption></figure><p>Now, let’s add “hooks” section in our package.json file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/584/1*wOPlbu4IuNZRyNWDMDH2LQ.png" /></figure><p>This tells Husky to run jshint index.js when the user type git commit.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3c2ed53a372177930db9c168159b59f6/href">https://medium.com/media/3c2ed53a372177930db9c168159b59f6/href</a></iframe><p>Next, we set up a .jshintrc file with basic linting rules:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e99c8dc3250e0dde7158efb0d73c406e/href">https://medium.com/media/e99c8dc3250e0dde7158efb0d73c406e/href</a></iframe><p>Then we’ll create an index.js file that violates some of these rules:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c1259a288721548bef062abcff2facc6/href">https://medium.com/media/c1259a288721548bef062abcff2facc6/href</a></iframe><p>Now, let&#39;s commit the changes and if you have done everything correctly, you should see something like the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/863/1*xlWKMMvTenHPhf2-ku7Dkg.png" /><figcaption>Commit failed by husky</figcaption></figure><p>Isn’t that amazing? No more bad code, no more buggy code, and no missing semicolons!</p><p>Let’s solve the errors and again commit the changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/627/1*tHCrld8gv-A0lDpBgY_REA.png" /><figcaption>Successfully committed</figcaption></figure><p>What if I want to skip it?</p><p>Shame on you! You should always run it, but for the rare cases where you want to skip it... you can add --no-verifyto flag bypass it, so the full command would be:</p><pre>$ git commit -m ‘<strong>SHAME ON ME</strong>’ --no-verify</pre><p>You can use it for tons of other things, for instance, you can let husky run your tests before every commit or push, or even clean up directories or run some grunt or gulp tasks… the possibilities are endless!</p><h3>Conclusion</h3><p>Git hooks are simple scripts that run before or after certain actions. They are useful for a variety of tasks, but primarily I find them useful for client-side validation so simple mistakes can be prevented. For example, you can test syntax on files being committed, you can even have tests run. I have written hooks that validate the JS code, run JSHint to a standard, and a lot more. Hooks can be written in any language the environment can work with.</p><p>Hope you have learned something new !! Please don’t forget to share and thanks for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bad9afcbb1b3" width="1" height="1" alt=""><hr><p><a href="https://codeburst.io/understanding-git-hooks-in-the-easiest-way-bad9afcbb1b3">Understanding git hooks in the easiest way</a> was originally published in <a href="https://codeburst.io/">codeburst</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Optimize your repository using Git GC]]></title>
            <link>https://codeburst.io/optimize-your-repository-using-git-gc-c4675ed8b7b2?source=rss-e6f25903ed6c------2</link>
            <guid isPermaLink="false">https://medium.com/p/c4675ed8b7b2</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[garbage-collection]]></category>
            <category><![CDATA[git]]></category>
            <dc:creator><![CDATA[Amit Prajapati]]></dc:creator>
            <pubDate>Sat, 16 May 2020 05:25:59 GMT</pubDate>
            <atom:updated>2020-07-15T15:01:23.596Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/822/1*HURoriNXjq4CqqouoRA_-w.png" /></figure><p><strong>Hello Techies 👨🏻‍💻</strong></p><p>Once again, I’ve come up with an interesting topic i.e how git optimizes its repository. If you want to understand this concept better then read through the article!</p><blockquote>Today’s Inspiration: “Little things make a big difference.”</blockquote><p>So let’s get started… 😃</p><p>Before we deep dive into the working of GC. Let’s understand why we need garbage collection in git. As some of you may know, the concept of garbage collection is originated in <em>High-Level</em> Programming Languages i.e <em>C</em>, <em>Java, </em>and <em>C++ </em>because of <em>memory management</em>.</p><p>In the <strong>Java </strong>programming language, <em>dynamic memory allocation</em> of objects is achieved using the <strong><em>new </em></strong>operator. Once an object is created, it uses some memory and the memory remains allocated until there are references for the use of the object. When there are no references for an object, it is assumed to be no longer needed and the memory occupied by the object can be reclaimed. There is no explicit need to destroy an object as java handles the de-allocation automatically. But in case of <strong>C++,</strong> you have to do manually de-allocation of objects.</p><p>The same thing happens in git as well. It reduces the disk size by cleaning up unnecessary objects. An object (<em>blobs</em>, <em>trees</em>, and <em>commits</em>) with SHA say — b15cae53e0f642d6804f060c02a83dbc3a1fb7ca will be stored at .git/objects/b1/5cae53e0f642d6804f060c02a83dbc3a1fb7ca (<em>the split in first two characters to improve performance of the file system as now not all objects are stored in the same directory</em>). Objects stored as above are referred to as<em> Loose objects</em>. The <em>Loose object</em> is simply a compressed data stored in a single file on disk. Every object is written to a separate file.</p><p>Git is a<em> content-addressable</em> file system i.e. it takes an object and stores it in files addressable by hashes. If you’re not aware of these objects then I will highly recommend you to go through this <a href="https://medium.com/mindorks/what-is-git-object-model-6009c271ca66">link</a>.</p><p>Let me give you some basic introduction of objects:</p><ul><li>A <strong>“blob”</strong> is used to store file data- it is generally a file.</li><li>A <strong>“tree”</strong> is basically like a directory- it references a bunch of other trees and blobs (i.e. files and sub-directories).</li><li>A <strong>“commit”</strong> object holds metadata for each change introduced in the repository, including the <em>author</em>, <em>committer</em>, <em>commit-data</em>, and <em>log- messages</em>.</li></ul><p>The git gc command cleans up unnecessary files and optimizes the local repository. GitHub runs this operation on its hosted repositories automatically on a regular basis based on a variety of triggers. Locally you can run it at any time. Running it won&#39;t have any adverse effect on your repository.</p><p><em>Lately</em>, I have been using <em>GitHub </em>and I’m wondering, What is the repository limit for files hosted on<em> github.com</em>. I’ve been wondering this because I was thinking of using <em>GitLab </em>since it allows <strong>10GB</strong> for each repository.</p><p>As of December 2019, the <em>GitHub </em>docs say: We recommend repositories be kept under <strong>1GB</strong> each. Repositories have a <em>hard limit</em>(Maximum Value) of <strong>100GB</strong>. If you reach<strong> 75GB </strong>you’ll receive a warning from git in your terminal when you push. This limit is easy to stay within if large files are kept out of the repository. If your repository exceeds <strong>1GB</strong>, you might receive a polite email from GitHub support requesting that you reduce the size of the repository to bring it down back.</p><p>If you own the <strong>repo</strong>, you can find the exact <strong>size</strong> by opening your Account Settings &gt; Repositories (<a href="https://github.com/settings/repositories">https://github.com/settings/repositories</a>), and the repo size is displayed next to its designation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/711/1*boPimy806_fp8ApiSY24ug.png" /></figure><p>In my case, the size is only in <strong>KB </strong>but when you work on actual real-world projects the size may be in <strong>MB </strong>or <strong>GB</strong>. So, we have to maintain our repository size using git gc command by removing <em>unreachable objects</em>.</p><p>When you start up with your repo, you mostly have loose objects. As the number goes high, it becomes inefficient and they are stored in a <strong><em>pack file</em></strong>. Such objects are called<strong> <em>packed objects</em></strong>.</p><p>Now, Let’s see the working of GC with an example:</p><p>Let’s initialize a new repository called “<em>gc_example</em>” with <em>git init.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/733/1*lNL-a8_7XT_bSbwHYSgZdg.png" /></figure><p>Let’s make a commit in this new repo.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/869/1*vb50o-luyp_Xf7jaQUbefA.png" /></figure><p>Let’s see how many objects do we have into this in .git/objects folder by using the command find .git/objects -type f .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*f2v_6wwCctrG_5DZTFxZ9Q.png" /></figure><p>What we can see now is that we have 3 objects and the SHA-1 of the object. We can also check the type of the object and the contents of the objects using git cat-file command.</p><p>These three objects are of different types are blobs, tree, and commit. Let’s view one by one.</p><p>This object is a type of commit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/803/1*CvrFSeaPTBfhNUhyaYTmWw.png" /><figcaption>commit object</figcaption></figure><p>This object is a type of blob by using -p option you can see the contents of a file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/722/1*qNNMXP0Uk_-hAMAa_NW7GQ.png" /><figcaption>blob object</figcaption></figure><p>The <em>blob </em>gives us the content of the file but it doesn’t tell us the source of the content so here comes the <em>tree </em>object which gives information about the name of the file and contains the reference of a blob object.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/821/1*m1N8rkz9JTlP9UaLejO0wQ.png" /><figcaption>tree object</figcaption></figure><p>Here, we have all the information that we need now and everything is nice and clean but one downside of this approach is that if we try to do small changes into this <strong><em>foo_bar.txt</em></strong> file and we’ll recommit again we will see that git creates as a new completely blob file that contains the whole foo_bar.txt file generating basically our duplicates of the file every time that we commit and to show you this problem I created another proposal that is exactly like this one so it’s a brand new proposal with my single file but the file instead of containing just “<em>hello world</em>” contains more than 10k line of code so it’s a really big repository.</p><p>I’m inside this new repository and so you can see that we have only one file and this file is too big containing <strong>2.1M</strong> of data and also we have only one commit.</p><p><strong>ls -l</strong>: Lists more information about all the files/folders in the current directory, one file/folder per line.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/816/1*ezr4ZgbEAhLDdQhCSuByiA.png" /></figure><p>We can see the list of objects inside this repository with a little bit more detail than what we did before with a different command that is <strong>git cat-file</strong> and then two options [<em> — batch-check</em>] and [<em> — batch-all-objects</em>].</p><p>If --batch or --batch-check is given, <em>cat-file</em> will read objects from <strong><em>stdin</em></strong><em>(I</em>s <em>an input stream where data is sent to and read by a program)</em>, one per line, and print information about them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/836/1*5Ti7htRvrl0agpMB18NRdg.png" /></figure><p>Here we have a list of objects with the left the SHA-1 of the object than on the right we have the type of the object and the size this object takes on the disk. Now, I will try to append one line to this file and recommit again and we can see how many objects are then created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/971/1*Td5oDgOyLP9YQMTGQHF4MA.png" /><figcaption>second commit</figcaption></figure><p>Let’s print again the list of objects.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/815/1*5-3d5NFuxIJ_cHmS41os5Q.png" /></figure><p>Now, we have now <em>six </em>objects that is what we expect but the bad thing is that we have a two <em>blob </em>object that contains a basically a duplicate of the file and each of this object takes <strong>2.1M</strong> of data.</p><p>Now, I will show you how we can reduce the size of these two objects take. We can finally try to reduce the size of this repository, reducing the size of the repository is done by a common little it’s called <strong>git gc </strong>this stands for git garbage collection and this process usually automatically launches it from git. whenever you push your repository to live remote or when you really a lot of object into your repository this can vary depends on your configuration or the tools that you are using so we will see now how we can execute this garbage collection manually, to execute the garbage collection we just need to run the <strong>git gc</strong> command and we can pass the parameter to this command this is <strong>--aggressive </strong>that means that this command should be a little more aggressive on saving space instead of saving a CPU.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/798/1*iZEPynhZQVbIY16HVvQquQ.png" /></figure><p>We expect now to have a less object or at least less space into this repository. Let’s re-execute the command git cat-file --batch-check --batch-all-objects to list all the objects. This command tells us that we have still six objects after performing a git gc operation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/809/1*cZ37A1VefJOUFRJs62IyTA.png" /></figure><p>But, what this command that doesn’t tell is that those objects are not stored into the objects file like it was at the beginning of this blog and we can see this checking directly into the file system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/952/1*xqxtnNcDYDrABlvmRv4gYg.png" /></figure><p>As you see, there is no more objects file. Instead there one <strong><em>pack </em></strong>and <strong><em>index </em></strong>file and this pack file it’s a binary object that contains inside all the objects that we had before but in a more efficient way also we have the <strong>.idx</strong> file that is the index because the pack is a binary file so we need to keep track of the offset where all the information is stored and all this offset is stored into this .idx file. If we look into this file we should be able to see our older objects. So there is one command in git called git verify-pack -v pack_file_path which shows you the content of the pack file. The -v option is called verbose.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cmJNxPmHp0LH-aVcCc__pw.png" /></figure><p>As we expect that this pack file contains a six object containing two commits, tree, and blobs but what is really interesting is that the two blobs are not occupying the same space on disk the blob 31bb368 SHA1 here occupies 2.1M while the 6b73b4b SHA1 occupies only 77. Why is this? It’s because the blob 6b73b4b here contains now only the difference does not contain the whole file and even better we can see this blob 31bb368 here is exactly the same SHA1 of the object that we store before. So we know this one is the object with the additional line so is the latest object while this one 6b73b4b is the oldest object.</p><p>We can also understand how git stores information into the pack file because this blob 31bb368 here is the most recent subversion of the file so we know that’s the inside of the pack file. The older blob 6b73b4b only contains the difference of the foo_bar.txt file. While for all the previous commit git stores all the difference into a blob that contains again the difference and a reference to the newest version of the file. We were able to reduce the size of the repository by almost 50%.</p><p><strong>Conclusion</strong></p><p>Users are encouraged to run this task on a regular basis within each repository to maintain good disk utilization and good operating performance.</p><p>Hope you will like this! Thank you &amp; Keep Learning :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c4675ed8b7b2" width="1" height="1" alt=""><hr><p><a href="https://codeburst.io/optimize-your-repository-using-git-gc-c4675ed8b7b2">Optimize your repository using Git GC</a> was originally published in <a href="https://codeburst.io/">codeburst</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is git blame & git clean]]></title>
            <link>https://medium.com/mindorks/what-is-git-blame-git-clean-ef8a600af37e?source=rss-e6f25903ed6c------2</link>
            <guid isPermaLink="false">https://medium.com/p/ef8a600af37e</guid>
            <category><![CDATA[git-clean]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[git-blame]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[software-testing]]></category>
            <dc:creator><![CDATA[Amit Prajapati]]></dc:creator>
            <pubDate>Fri, 07 Feb 2020 10:55:05 GMT</pubDate>
            <atom:updated>2020-02-07T10:55:05.167Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/823/1*T25VPl1MZyF0iqDtGJwqnw.png" /></figure><blockquote>Today’s Inspiration</blockquote><blockquote>“Change is the end result of all true learning”.</blockquote><p>Let’s get started… 👨‍💻</p><p>In Git, we know sometimes, someone can edit/delete something, after that the project starts popping up errors everywhere.</p><p>The first action is finding the error, then if your team are more than four developers, spotting who introduced(by checking commits) the error could be painful and this is the second action. Knowing who did it. Luckily, we can use a not know(for beginners) command git blame.</p><p>Basically, we execute <strong>git blame</strong> path_of_the_file_where_the_error_is or directly the name of the file.</p><p>Git blame is an awesome tracking command for Git. It shows the author information of each line of the project’s last modified source file. You can find the author name, author email, the commit hash etc of the last modified source file line by line. You will see shortly what I mean practically.</p><p><strong>e.g:</strong> I have a repository with commit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*KGup1t1Pq3gX14ONSrXdww.png" /><figcaption>repo with commit</figcaption></figure><p>Suppose, I or someone changed the files in past. When trying to run the application we got an error. If you want to know who changed the code with the date and time, you can do it with<strong> git blame</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/878/1*ztGLwMMGHeRz9lVQKxgGfA.png" /><figcaption>index.html file</figcaption></figure><p>When executing <strong>git blame</strong> command, you can see the name, time and date in each line of code.</p><p>As you see, we have an error in line number <strong>6</strong>, forget to add ‘/’ in &lt;p&gt; tag. I am responsible for this error… 😐</p><p>With this command, we can figure out the error quickly.</p><p>There are various options we can use with <strong>git blame</strong> command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/915/1*rJOpnT4BQJgzQXHbSlhF-w.png" /><figcaption>options available in blame command</figcaption></figure><p>Let use some of these options:</p><ul><li><strong>-L &lt;start&gt;,&lt;end&gt;</strong></li></ul><p>Annotate only the given line range. May be specified multiple times. Overlapping ranges are allowed. The &lt;start&gt; and &lt;end&gt; is the range that you have to provide. e.g: -L 2, 8 . This will display the line ranging from line <strong>2 </strong>to line <strong>8</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/831/1*ZWPnNrrSgyELqjX7f99Ifg.png" /><figcaption>option -L &lt;start&gt;, &lt;end&gt;</figcaption></figure><ul><li><strong>-e, --show-email</strong></li></ul><p>If you want to view email id instead of name then you have to use <strong>-e</strong> option.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/929/1*Qrltq115mL3E7-E_Am0J-A.png" /><figcaption>option -e</figcaption></figure><ul><li><strong>-f, --show-name</strong></li></ul><p>If you also want to view the <em>file name</em> with name and timestamp then use <strong>-f</strong> option.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/932/1*kIZmkg0i-HQTY_T5Qd-eOw.png" /><figcaption>option -f</figcaption></figure><h4>Aliasing Git Blame</h4><p>Some programmers don’t like the word ‘blame’, because of the negative connotation ‘blaming someone’ brings with it. Also, the tool is rarely (if ever) used for blaming someone, but rather to ask for advice or understand the history of a file. Therefore, sometimes people use an alias to change git blame to something which sounds a bit nicer such as git who, git history or git praise. To do that you simply add a git alias like this:</p><pre><strong>git config</strong> --global alias.who blame</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/913/1*yJfF_iubMzZBAAe7vXktZg.png" /><figcaption>change blame to who</figcaption></figure><h4>Keep your git directory clean with `git clean` command</h4><p>Do you have your git directory full of <strong><em>untracked</em></strong><em> </em>files and it starts to bothers you when you are picking the changes for commit? Well, I have a tip for you!</p><p>The command git clean operates on untracked files. Untracked files are files that have been created within your repo&#39;s working directory but have not yet been added to the repository&#39;s tracking index using the git add command.</p><p>This is a builtin command to<em> clean up</em> the untracked files. Be careful with this one, it deletes files permanently!</p><p><strong>e.g: </strong>These are the untracked files.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/874/1*YxsFq7-mKyQxhXGl_5Jwlw.png" /><figcaption>Untracked files</figcaption></figure><p>As you see we have <strong>3 </strong>untracked files.</p><p>Let’s delete the <strong>bye.html</strong> file because we don’t need this file anymore.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1003/1*btgGo0pPBEdeIyQQ3GHQrQ.png" /><figcaption>fatal error</figcaption></figure><p>At this point, executing the default git clean command may produce a fatal error. The example above demonstrates what this may look like. By default, Git is globally configured to require that git clean be passed a &quot;force&quot; option to initiate. This is an important safety mechanism. When finally executed git clean is not undo-able. When fully executed, git clean will make a hard filesystem deletion, similar to executing the command line rm utility. Make sure you really want to delete the untracked files before you run it.</p><p>So, to delete this file we have to use -f (force) option.</p><ul><li><strong>-f or --force</strong></li></ul><p>The force option initiates the actual deletion of untracked files from the current directory. Force is required unless the clean.requireForce configuration option is set to false. Let us now execute git clean in our repo.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/827/1*c8D7QD-6FPnwYDy8jHIzWg.png" /><figcaption>file deleted</figcaption></figure><p>The command will output the files that are removed. You can see here that <strong><em>bye.html</em></strong> has been removed. Executing git status at this point or doing a ls will show that untracked_file has been deleted and is nowhere to be found. By default git clean -f will operate on all the current directory untracked files.</p><ul><li><strong>-f -d</strong></li></ul><p>If you also want to remove directories, run <strong>git clean</strong> -f -d &lt;directory_name&gt; .</p><ul><li><strong>-n</strong></li></ul><p>The -n option will perform a “dry run” of git clean. This will show you which files are going to be removed without actually removing them. It is a best practice to always first perform a dry run of git clean. We can demonstrate this option in the demo repo we created earlier.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/586/1*T-oLBl_xD27uoxOdj_C48A.png" /><figcaption>list of files and directories</figcaption></figure><p>The output tells us the will be removed when the git clean command is executed. Notice that the directories are also listed here with -d option. By default git clean will not operate recursively on directories. This is another safety mechanism to prevent accidental permanent deletion.</p><p>Hope you will learn a new topic from this article.</p><p>Thank you &amp; Peace. ✌</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ef8a600af37e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mindorks/what-is-git-blame-git-clean-ef8a600af37e">What is git blame &amp; git clean</a> was originally published in <a href="https://medium.com/mindorks">MindOrks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What are refs & git reflog]]></title>
            <link>https://medium.com/mindorks/what-are-refs-git-reflog-8e28ded5d2c0?source=rss-e6f25903ed6c------2</link>
            <guid isPermaLink="false">https://medium.com/p/8e28ded5d2c0</guid>
            <category><![CDATA[git]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[git-reflog]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Amit Prajapati]]></dc:creator>
            <pubDate>Mon, 03 Feb 2020 03:38:32 GMT</pubDate>
            <atom:updated>2020-02-03T03:38:32.380Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/833/1*FDvKZ3_UYcJ0hOJw_84uOA.png" /></figure><blockquote>Today’s Inspiration</blockquote><blockquote>“Strive for progress, not perfection.”</blockquote><p>Let’s get started… 👩‍💻</p><p>In the <a href="https://medium.com/mindorks/what-is-git-object-model-6009c271ca66">previous blog</a>, we’ve seen how git store objects internally, which makes it fast and flexible. In this blog, we’ll talk about <strong>refs </strong>and <strong>reflog</strong>.</p><h4><strong>Refs</strong></h4><p>We want to manipulate objects quite often in Git, it’s important to know their hashes. You could run all your Git commands referencing each object’s hash, like <strong>git show </strong>d377d67, but that would require you to remember the hash of every object you want to manipulate.</p><p>To save you from having to memorize these hashes, Git has references, or refs. A reference is simply a file stored somewhere in .git/refs, containing the hash of a commit object.</p><p>Refs are stored as normal text files in the .git/refs directory. To explore the refs in one of your repositories, navigate to .git/refs. You should see the following structure, but it will contain different files depending on what branches, tags, and remotes you have in your repo:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QI18K6Jx0KipyOAmA8YrCA.png" /><figcaption>Inside .git/refs directory</figcaption></figure><p>The heads directory defines all of the local branches in your repository. Each filename matches the name of the corresponding branch, and inside the file, you’ll find a commit hash. This commit hash is the location of the tip of the branch. To verify this, try running the following two commands from the root of the Git repository:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/811/1*OsMilPUYcTKnDJVw6sNHPQ.png" /><figcaption>hash returned by the cat command</figcaption></figure><p>The commit hash returned by the cat command should match the commit ID displayed by git log.</p><p>To change the location of the master branch, all Git has to do is change the contents of the refs/heads/master file. Similarly, creating a new branch is simply a matter of writing a commit hash to a new file. This is part of the reason why Git branches are so lightweight compared to SVN.</p><p>Git consistently uses the term rev in plumbing commands as short for &quot;revision&quot; and generally meaning the 40-character SHA1 hash for a commit. The command rev-list for example prints a list of 40-char commit hashes for a branch or whatever.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/785/1*wayv3D8xpBMdHw_NjWDV1w.png" /></figure><p>The tags directory works the exact same way, but it contains tags instead of branches.</p><p>The remotes directory lists all remote repositories that you created with git remote as separate subdirectories. Inside each one, you’ll find all the remote branches that have been fetched into your repository.</p><h4>Special Refs</h4><p>In addition to the refs directory, there are a few special refs that reside in the top-level .git directory. They are listed below:</p><ul><li>HEAD – The currently checked-out commit/branch.</li><li>FETCH_HEAD – The most recently fetched branch from a remote repo.</li><li>ORIG_HEAD – A backup reference to HEAD before drastic changes to it.</li><li>MERGE_HEAD – The commit(s) that you’re merging into the current branch with git merge.</li><li>CHERRY_PICK_HEAD – The commit that you’re cherry-picking.</li></ul><p>These refs are all created and updated by Git when necessary. For example, The git pull command first runs git fetch, which updates the FETCH_HEAD reference. Then, it runs git merge FETCH_HEAD to finish pulling the fetched branches into the repository. Of course, you can use all of these like any other ref, as I’m sure you’ve done with HEAD.</p><p>These files contain different content depending on their type and the state of your repository. The HEAD ref can contain either a <strong>symbolic ref</strong>, which is simply a reference to another ref instead of a commit hash, or a commit hash. For example, take a look at the contents of HEAD when you’re on the master branch:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/644/1*ExIPggW8H2SB_n4jjjUEBQ.png" /></figure><p>This will give output ref: refs/heads/master, which means that HEAD points to the refs/heads/master ref. This is how Git knows that the master branch is currently checked out. If you were to switch to another branch, the contents HEAD would be updated to reflect the new branch. But, if you were to check out a commit instead of a branch, HEAD would contain a commit hash instead of a symbolic ref. This is how Git knows that it’s in a detached HEAD state.</p><p>“<em>Have you ever faced a problem, where you have lost a branch, whose source code was not yet merged in the ‘release’ branch or the ‘main’ branch? What if you want to regenerate a deleted branch though its work has already been merged into the main branch? Well, the only solution to such scenarios is </em><strong><em>Git Reflog</em></strong>.”</p><p>Through this article on Git Reflog, I will help you understand the scenario in which your work on a branch could be lost and how to recover the branch. Also, this article will highlight the approach you could take to prevent the unintended loss of a branch while working in a large project.</p><p>Consider a scenario, where a maintainer has to merge many features from different collaborators and then delete them eventually; but the branch is deleted accidentally before the work could be merged?</p><h4>What is Git Reflog?</h4><p>The reflog is Git’s safety net. It records almost every change you make in your repository such as creating (branches or tags). You can think of it is a chronological history of everything you’ve done in your local repo. Reference logs such as the commit snapshot of when the branch was created or cloned, checked-out, renamed, or any commits made on the branch are maintained by Git and listed by the ‘<strong>reflog</strong>’ command.</p><p>A Git reflog is a list of hashes, which represent where you have been during commits. Each time a branch is updated to point to a new reference, an entry is written in the reflog to say where you were. Since the branch is updated whenever you commit, the git reflog has a nice effect of storing your local developer’s history.</p><p><strong><em>Note: </em></strong><em>The branch will be recoverable from your working directory only if the branch ever existed in your local repository i.e. the branch was either created locally or checked-out from a remote repository in your local repository for Git to store its reference history logs.</em></p><p>This command has to be executed in the repository that had the lost branch. If you consider the remote repository situation, then you have to execute the reflog command on the developer’s machine who had the branch.</p><p>Let’s understand the concept with an example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/684/1*InANcYfMv8BtAzlNWj6eeQ.png" /><figcaption>Initializes a repo with one commit</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*e9PYv1RiVHOsl6E7NvXStQ.png" /><figcaption>Created a new ‘dev-branch’</figcaption></figure><p>Created another branch named “<strong><em>dev-branch</em></strong>” with one commit.</p><p>Now, let us list the branches which are not merged into master.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/445/1*BbiumxJyy5p3BwZjUBnI_A.png" /><figcaption>no merged branch</figcaption></figure><p>We have a ‘<strong>dev-branch’</strong> branch which is not yet merged.</p><p>If you try to delete one of the branches with un-finished work say “<strong><em>dev-branch</em></strong>” branch, git display a warning message.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/738/1*4aFIgro5l8WdlNuNJ6f5qw.png" /><figcaption>Warning while deleting the branch</figcaption></figure><p>Consider a scenario where a developer merges the feature branch into the main branch locally and then deletes the feature branch using the ‘<strong>git branch</strong>’ command with the “<strong>-d</strong>” flag as seen in the earlier screenshots.</p><p>It could also happen that the developer decides to trash the changes on the branch and decides to delete the branch without merging it with any other branch using the following command:</p><pre><strong>git branch</strong> -D  ‘branch_name’</pre><p>With the above command, the developer forcefully deletes the branch by overriding the git warning.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/462/1*D53IiFveXtB-xuRUwkcx9g.png" /><figcaption>branch deleted</figcaption></figure><p>Now, the ‘<strong>dev-branch</strong>’ branch will no longer be listed when you run the ‘<strong>git branch</strong>’ command. So, your work saved on this branch will be lost.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/491/1*wbMttW-zg4UAKErZ-foQow.png" /><figcaption>We left with the only master branch</figcaption></figure><h4>Recover a deleted branch using Git Reflog</h4><p>If the maintainer cannot recover the branch, then the owner of the branch who deleted it must recover from his/her local reflogs.</p><p><strong>Step 1: History logs of all the references</strong></p><p>Get a list of all the local recorded history logs for all the references (‘master’ and ‘dev-branch’) in this repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/901/1*CiYWfR9p5BhTeQSEp8iDqw.png" /><figcaption>local repo history</figcaption></figure><p><strong>Step 2: Identify the history stamp</strong></p><p>As you can refer from the above snapshot, the<strong> Highlighted commit id: 8db9460 along with the HEAD pointer index:1</strong> is the one when ‘<strong>dev-branch</strong>’ branch was created from the current HEAD pointer pointing to your latest work with the latest commit in ‘<strong>dev-branch</strong>’ branch.</p><p><strong>Step 3: Recover</strong></p><p>To recover back the <strong>‘dev-branch’</strong> branch use the command ‘<strong>git checkout</strong>’ passing the HEAD pointer reference with the index id — 1. This is the pointer reference when ‘<strong>dev-branch</strong>’ branch was created long commit id highlighted in the output screenshot.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/595/1*11IIdDrb0nGQRwbCA7P-qA.png" /><figcaption>‘dev-branch’ branch recovered</figcaption></figure><p>Yay! ‘dev-branch’ branch is recovered back with all of our source code.</p><p>Now, that you know how to restore a branch, let me tell you what work is restored when a deleted branch is recovered.</p><p><strong>What work is restored when the deleted branch is recovered?</strong></p><p>The files which were stashed and saved in the stash index list will be recovered back. Any untracked files will be lost. Also, it is a good idea to always stage and commit your work or stash them.</p><p>To open reflog manual page use the command <strong>git reflog </strong>--help .</p><p>Thanks for reading. Soon I will post some more articles on git.</p><p>Till then <strong>happy learning</strong> and <strong>keep reading</strong>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8e28ded5d2c0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mindorks/what-are-refs-git-reflog-8e28ded5d2c0">What are refs &amp; git reflog</a> was originally published in <a href="https://medium.com/mindorks">MindOrks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is Golang]]></title>
            <link>https://medium.com/devops-dudes/what-is-golang-66b5c44fad85?source=rss-e6f25903ed6c------2</link>
            <guid isPermaLink="false">https://medium.com/p/66b5c44fad85</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[go]]></category>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[Amit Prajapati]]></dc:creator>
            <pubDate>Thu, 14 Nov 2019 21:26:31 GMT</pubDate>
            <atom:updated>2021-10-04T15:33:14.057Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yIZB_G7Dj9VDzdv35-3SGw.png" /></figure><p><strong><em>Hello Folks</em></strong>,</p><p>In this blog, we’ll learn about “<em>The Most Promising Language”</em> i.e. <strong>Golang</strong> and also how to install it.</p><p>So, Let’s get started. 🙂</p><p><strong><em>Golang </em></strong>is a <em>programming language </em>initially developed at Google in the year 2007 by Robert Griesemer, Rob Pike, and Ken Thompson and it’s very promising in fact that’s what <em>JetBrains</em> says. So<em> JetBrains</em> recently has done a poll with 7000 developers and this is the takeaways.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RJ3fNj1qaqVdBQbdEpE75Q.png" /></figure><p>In the takeaways, <strong>JAVA</strong> is the most popular primary language as everyone knows about it and the <strong>JavaScript </strong>is a most used overall language and then <strong>Python</strong> the most studied language because it’s easy to learn and the most promising one is the <strong>Go</strong> language.</p><p>In fact, <strong>Hyperledger Fabric</strong> (<em>Is modular blockchain framework which acts as a foundation for developing blockchain-based products</em>) promotes <strong>Go </strong>language as their primary language. There are certain technologies like <em>docker</em>, <em>Kubernetes </em>they are developed in <strong>Go </strong>language.</p><p><strong>Go </strong>programming language is a <strong><em>statically-typed</em></strong> (which means variables types are explicitly declared and thus are determined at compile time) language with syntax similar to that of<strong> C </strong>and <strong>C++</strong>. It provides garbage collection, type safety <em>(means the type of the variable should be safe. </em><strong><em>e.g</em></strong><em>: can’t save or initialized a variable of string type with an integer),</em> dynamic-typing capability, many advanced built-in types such as variable-length arrays and key-value maps. It also provides a rich standard library. Go compiles quickly to machine code yet has the convenience of garbage collection and the power of run-time reflection <em>(Reflection can be used for observing and modifying program execution at runtime)</em>. It’s fast, statically typed, compiled language that feels like a dynamically typed, interpreted language.</p><p>A Go program can vary from 3 lines to millions of lines and it should also be written into one or more text files with extension “.go”; for example, hello.go.</p><p>Now, if you want to do experiment with ‘<em>Go</em>’ they provide you with a playground. <em>Yes</em>, you don’t have to do setup just we do need setup for if you want to make a project but if you want to learn they have a playground.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SJAbgbrYnv_99jcxOERqOA.png" /></figure><p>Here you can just click on this “<a href="https://play.golang.org/p/MAohLsrz7JQ">Open in Playground</a>” it will open a new tab with this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/726/1*lTms3Db7-yfGS19IrwbWBQ.png" /></figure><p>Here you can write code or you can just simply click on “<em>Run</em>” what it will do it will send your script to the server for the compilation because you don’t have setup on your machine and then you will get the output.<strong><em> Hurray!!</em></strong> you run your first code without any setup.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*Qzjp4e0gOU9pJjDnTZkbpA.png" /></figure><p>Now, if you know the basics of programming may be Java, C, or C++ you will be understanding some of it. So basically in Java we to create packages same way we have a package here sometimes we have to import packages because if we use some external features or if you want to use any feature you need to import some packages that are what we are doing here. We are importing a package “<em>fmt</em>” which is for format and of course, if you want to run this code we have to write the main method or a function, so in “Go” we call them as functions and inside this, you just print “Hello World”.</p><p>Now In terms of comparison between different languages “<strong>Go</strong>”<strong> </strong>is faster it has an amazing feature and the best part it’s a new language. When I say new it’s not that new it’s been almost 10 years now but compared to another language it’s new it has some awesome features to work with and then the advantage would be if you learn go you will be probably among the few developers available in the market who knows “<strong>Go</strong>” and you’ll be one of them.</p><h3>Installation of Golang</h3><p>Now, if you want to download “<strong>Go</strong>” you do it from <a href="https://golang.org/">here</a> you can use different IDE such as <a href="https://www.eclipse.org/downloads/"><em>Eclipse</em></a><em>, </em><a href="https://www.jetbrains.com/idea/download/#section=windows"><em>IntelliJ IDEA</em></a><em>, </em><a href="https://www.jetbrains.com/go/"><em>GoLand</em></a><em> or vs</em><a href="https://code.visualstudio.com/download"><em> code</em></a> whichever favourite IDE you prefer you can use that, it just needs a “<strong>Go</strong>” compiler.</p><p>Here I will show you the installation of “<strong>Go</strong>” in <em>VS Code.</em></p><ol><li><strong>Go </strong>in Visual Studio Code</li></ol><p>Using the <strong>Go </strong>extension for Visual Studio Code, you get language features like IntelliSense, code navigation, symbol search, bracket matching, snippets, and many more that will help you in <em>Golang </em>development.</p><p>Firstly, you need to download the <a href="https://golang.org/"><strong>Golang</strong> </a>and <a href="https://code.visualstudio.com/download"><strong>VS Code</strong></a> setup.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GzVVqUcudVSwAhckteQJRQ.png" /></figure><p>If already downloaded, then install it on your machine like this in the image below 👇</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/648/1*emYrldwEpEW5rFkOgrSA0Q.png" /></figure><p>Click <strong>Next </strong>to continue the installation process.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/607/1*ZVCIb7la8D5a9t_HMOlONw.png" /></figure><p>Checked the checkbox to accept the terms in the License Agreement.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/770/1*qmDEHjRn_4oNZKl6iK-Gdw.png" /></figure><p>Click on <strong>Install </strong>to proceed with the installation process.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/1*LtyfKKK9WRc5URLl40IipQ.png" /></figure><p>Wait until it completes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*7yEg7i4l3PFdGVeqa7i80A.png" /></figure><p>Finally, your installation process of <strong>Go </strong>is completed.</p><p>Now, If you want to verify that the <strong><em>Go </em></strong>is installed in your machine or not, just open your cmd (command prompt) and write ‘<strong><em>go</em></strong>’. If you get an error like “<em>go command not found</em>” that means ‘<strong><em>go</em></strong>’ is not installed in your machine. If not then you’re good to go.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1005/1*YGV0JbrJNGpMO3dD1QCjkg.png" /></figure><p>Now, we need to set the <em>environment variables</em> for ‘<strong><em>go</em></strong>’. So the steps are as follows:</p><p>Your workspace can be located wherever you like, but we’ll use <strong>C:\go-work</strong> in this example.</p><p><strong>NOTE:</strong> GOPATH must not be the same path as your installation.</p><ul><li>Create a folder at C:\go-work .</li><li>Right-click on “<em>Start</em>” and click on “<em>Control Panel</em>”, select “<em>System and Security</em>”, then click on “<em>System</em>”.</li><li>From the menu on the left, select the “<em>Advanced systems settings</em>”.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/863/1*47DvFTZrLik7OxTGB3Qn5w.png" /></figure><ul><li>Click the “Environment Variables” button at the bottom.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/426/1*e-yeq7WBq2IzHlupCSdVpQ.png" /></figure><ul><li>Click “New” from the “User variables” section.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/626/1*7zqRdAL852T-bWxujGu1jQ.png" /><figcaption>Select GOPATH from the User variable and click on ‘New’.</figcaption></figure><ul><li>Type GOPATH into the “Variable name” field.</li><li>Type C:\go-work into the “Variable value” field.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/676/1*RI6yQhR3Z-eMwO4LA9axvQ.png" /></figure><ul><li>Click Ok.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/629/1*HelXNIm3-4TV5eM31-OVig.png" /></figure><p>Then, click <em>OK </em>one more time.</p><p>Now, we have to open the folder go-work inside the <strong><em>VS Code</em></strong> through command prompt. Let’s see how can we do it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/980/1*svgnN30GLvvZqw6Vd6-vsA.png" /></figure><p>The command code . will open VS Code Editor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QfUl7P1XYHIl8l_FOhawng.png" /></figure><p>To work with “<strong>Go</strong>” you need to install a plugin inside <em>VS Code</em>. Just by tapping to the <strong><em>Extension</em></strong> section in<em> VS Code</em> or use a shortcut key shift + ctrl + X .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tfN3ndys39AM_y-EJniBlw.png" /></figure><p>Now, we just need to install this plugin.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I6NqAjESsJQRS2PCMFw3jA.png" /></figure><p>We have successfully installed the ‘<strong><em>go</em></strong>’ and now we are able to write our first program in ‘<strong><em>go</em></strong>’ using the <em>VS Code</em>.</p><p>Inside go-work folder, we have created another folder named hello which contain one file named as main.go.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cYxV8e9BU_d1oQ7ZaCLQmw.png" /></figure><p><strong><em>Yay!!</em></strong> We successfully run our first <em>hello world program</em> in GO.</p><p>Hope it helps.</p><p>Keep Learning, Thank you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=66b5c44fad85" width="1" height="1" alt=""><hr><p><a href="https://medium.com/devops-dudes/what-is-golang-66b5c44fad85">What is Golang</a> was originally published in <a href="https://medium.com/devops-dudes">DevOps Dudes</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is Git Object Model]]></title>
            <link>https://medium.com/mindorks/what-is-git-object-model-6009c271ca66?source=rss-e6f25903ed6c------2</link>
            <guid isPermaLink="false">https://medium.com/p/6009c271ca66</guid>
            <category><![CDATA[object-model]]></category>
            <category><![CDATA[git]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Amit Prajapati]]></dc:creator>
            <pubDate>Thu, 26 Sep 2019 10:42:18 GMT</pubDate>
            <atom:updated>2019-11-02T10:11:05.450Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/675/1*LLE1eYnLqIdaudjj4fE1Vw.png" /></figure><blockquote>Today’s Motivation</blockquote><blockquote>“As long as you feel pain, you’re still alive. As long as you make mistakes, you’re still human. And as long as you keep trying, there’s still hope.”</blockquote><p>Get started… 👩‍💻</p><h4>What is repository</h4><p>A repository is simply a database containing all the information needed to retain and manage the revisions and history of a project. Within a repository, Git maintains two primary data structures, the <strong>object store</strong>, and <strong>index</strong>.</p><p>The <strong>object store</strong> is designed to be efficiently copied during a clone operation as part of the mechanism that supports a fully <strong>DVCS </strong>(Distributed Version Control System).</p><p>An <strong>index </strong>is <em>transitory information</em>, is private to a repository and can be created or modified on-demand as needed.</p><h4>The SHA (Secure Hash Algorithm)</h4><p>All the information needed to represent the history of a project is stored in files referenced by a <strong>40-digit</strong> “object name” that looks something like this:</p><pre>8hf67f4664981e4397625791c8eabbb5f2279a31</pre><p>You will see these <strong><em>40</em></strong>-character strings all over the place in <strong>Git</strong>. In each case, the name is calculated by taking the <em>SHA1 </em>hash of the contents of the object. The <em>SHA1 </em>hash has a cryptographic hash function. What that means to us is that it is virtually impossible to find two different objects with the same name. This has a number of advantages; among others:</p><ul><li>Git can quickly determine whether two objects are identical or not, just by comparing names.</li><li>Since object names are computed the same way in every repository, the same content stored in two repositories will always be stored under the same name.</li></ul><h4>Git Object Store</h4><p>It contains your original data files and all the log messages, author information, dates, and other information required to rebuild any revision or branch of the project.</p><p>Every object consists of three things- a <strong>type</strong>, a <strong>size</strong>, and <strong>content</strong>. The <em>size </em>is simply the size of the contents, the <em>content </em>depends on what type of object is, and there are four different types of objects: “<em>blob</em>”, “<em>tree</em>”, “<em>commit</em>”, and “<em>tag</em>”. Git stores these different types of objects in .git/objects.</p><ul><li>A <strong>“blob”</strong> is used to store file data- it is generally a file.</li><li>A <strong>“tree”</strong> is basically like a directory- it references a bunch of other trees and blobs (i.e. files and sub-directories).</li><li>A <strong>“commit”</strong> object holds metadata for each change introduced in the repository, including the <em>author</em>, <em>committer</em>, <em>commit-data</em>, and <em>log- messages</em>.</li><li>A <strong>“tag”</strong> object assigns an <em>arbitrary human-readable name</em> to a <em>specific object </em>usually a commit.</li></ul><h4>Different from SVN (Subversion)</h4><p>It is important to note that this is very different from most SCM (Source Code Management) systems that you may be familiar with. Subversion and CVS store the differences between one commit and the next. Git does not do this — it stores a snapshot of all the files in your project each time you commit. This is a very important concept to understand when using <strong>Git</strong>.</p><p>Here we make examples of each of these object types in a new repository.</p><p>First, we make the working tree and initialize the repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*JxmJoohJJlWw6fRwQyBGdg.png" /></figure><p>Git will inform us it has created a .git directory in our project’s directory so let’s take a quick peek at how it looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/669/1*Nk6uCvlmMAmwIGQsvPl5Jg.png" /></figure><p>Some of these files and directories may sound familiar to you ( particularly HEAD) but for now, we will focus on the .git/objects directory which is empty right now, but we will change that in a moment.</p><p>Let’s create an “<em>index</em>.<em>txt</em>” and “<em>README.md</em>” file with some content.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/779/1*Lt43KsDGW5pmtXDS0uwdAQ.png" /></figure><p>Now, let’s stage and commit them:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/672/1*88kG5CfcRnRRzL1xzrmc8A.png" /></figure><p>Okay, nothing special here, adding and committing — we’ve all “been there, done that”.</p><p>If we take a look again at our .git directory we can see that the .git/objects directory has some subdirectories and files now:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/697/1*c_kCe0sRw0dUJ-8R7cLJWw.png" /></figure><p><em>(Note: directories and files will have different names on your computer)</em></p><p>We will get back to .git/objects but for now, notice that every directory name is two characters long. Git generates a <strong>40</strong>- character checksum (SHA-1) hash for every object and the first two characters of that checksum are used as the <em>directory name</em> and other <strong>38 </strong>as a file <em>(object) name</em>.</p><p>The first kind of object that git creates when we commit some files are <strong>blob </strong>objects, in our case, we’ve two of them, one for each file we committed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/580/1*iVfKvADHdEMQCxoLluVhQw.png" /><figcaption>Blob objects associated with our index.txt and README.md files.</figcaption></figure><p>They contain snapshots of our files (the content of our files at the time of the commit) and have their checksum header.</p><blockquote><strong>Note</strong>: I’ll use the command <em>git cat-file</em> to show the contents of the hashed files in <em>.git/objects</em>, but <em>cat-file</em> is a relatively obscure git command that you will probably not need in your daily git work.</blockquote><p><strong>git-cat-file</strong> : Provides content or type and size information for repository objects.</p><p>There are multiple options in git cat-file command that we can use, but we mainly focus on <strong>-t</strong>, <strong>-s</strong>, <strong>-p</strong> options.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/813/1*Qh-iGsLnidKxNFDYT8t0xQ.png" /></figure><h4>Blob Object</h4><p><strong>Blob </strong>is an <em>abbreviation </em>for “<em>binary large object</em>”. The first kind of objects that git creates when we commit some files are blob objects, in our case “index.txt” and “README.md” files, one for each file we committed. A <strong><em>blob </em></strong>generally stores the <em>contents of a file</em>. The directory listing gave us the hash of the stored file named “<em>index.txt &amp; README.md</em> ”. This object is of type “<strong>blob</strong>” and contains the file snapshot.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/716/1*4sRuk6VuK8FisNbMcq0PVw.png" /></figure><p>We can look at blob object representing (for example) index.txt with the cat-file command:</p><pre>git cat-file blob 980a0d5f19a64b4b30a87d4206aade58726b60e3</pre><p>and we see that it contains our index.txt file’s content.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/701/1*2lO3z7AFw7CuBfwPNU_IRg.png" /></figure><p>From Git, we expect there will now be four objects in the directory in .git/objects :</p><ul><li>One storing the backup of index.txt and README.md files.</li><li>One storing the directory listing for the commit.</li><li>One storing the commit message.</li></ul><h4>Tree Object</h4><p>The next kind of objects git creates are <strong>tree </strong>objects. In our case, there is only one and it contains a list of all files in our project with a pointer to the blob object assigned to them (this is how git associates your files with their blob objects):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/547/1*sNQE9VaE7RlsJREOM5J9Iw.png" /><figcaption>Tree object pointing to blob objects</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/788/1*ZiEvyqtZs1JeGsdNrlJlvQ.png" /></figure><p>The <em>tree </em>object contains one line per file or subdirectory, with each line giving file permissions, <em>object type</em>, <em>object hash</em>, and <em>filename</em>. An <em>object </em>type is usually one of “<strong>blob</strong>” for a file or “<strong>tree</strong>” for a subdirectory.</p><p>Let’s try to understand, the output of the command git cat-file -p 5fbbad8 in the image below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/696/1*YEZR4PdySzvu6QKHSiCfpQ.png" /></figure><ul><li>The first part states the file’s permission i.e. <strong>100644</strong>. As you can see the file has <em>644 </em>permission (ignoring the 100). <strong>Permissions </strong>of <strong>600 </strong>mean that the owner has full read and write <strong><em>access </em></strong>to the file, while no other user can access the file. <strong>Permissions </strong>of <strong>644 </strong>mean that the owner of the file has read and write <strong><em>access</em></strong>, while the group members and other users on the system only have read <strong><em>access</em></strong>.</li><li>The second part states that the content of this entry is represented by a blob, rather than a tree.</li><li>The third part states the <em>hash </em>of the <strong><em>blob</em></strong>.</li><li>The fourth part states the filename.</li></ul><p>And finally, git creates a <strong>commit </strong>object that has a pointer to its tree object (along with some other information):</p><h4>Commit Object</h4><p>The commit object contains the directory tree object hash, parent commit hash, author, committer, date, and message.</p><p>Git log will show us the hash of the commit message:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/1*GP9YYViKr_EefTlUWT874g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/531/1*69EWy-tGmJYxP7lFK3Nukw.png" /><figcaption>Commit object points to its tree object</figcaption></figure><p>git cat-file -p shows the contents of the file associated with this hash.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/746/1*muSxnFHPMSOBqFHCQ0LIwQ.png" /></figure><p>As you can see, a commit is defined by:</p><ul><li>A <strong>tree</strong>: The SHA1 name of a tree object, representing the contents of a directory at a certain point in time.</li><li>A <strong>parent(s)</strong>: The SHA1 name of some number of commits which represent the immediately previous step(s) in the history of the project. The example above has <strong>no parent</strong>; merge commits may have more than one. A commit with <em>no parent</em> is called a “<strong>root</strong>” commit and represents the initial revision of a project. Each project must have at<strong> least one root</strong>.</li><li>An <strong>author</strong>: The name of the person responsible for this change, together with its date.</li><li>A <strong>committer</strong>: The name of the person who actually created the commit, with the date it was done. This may be different from the author; for example, if the author wrote a patch and emailed it to another person who used the patch to create the commit.</li><li>A <strong>comment </strong>describing the commit.</li></ul><p>A commit is usually created by git commit , which creates a commit whose parent is normally the current <strong>HEAD</strong>, and whose tree is taken from the content currently stored in the index.</p><h4>Tag Object</h4><p>A tag object contains an object name(called simply ‘<strong><em>object</em></strong>’), object type, tag name, the name of the person (“<strong><em>tagger</em></strong>”) who created the tag, and a message.</p><p>There is also a git type for <strong>annotated tags</strong>. We don’t have one of these yet, so let’s make one:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/859/1*owG5E0iZrfa4e--h6-N0AA.png" /></figure><p>This gives us a new object in .git/objects :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/704/1*gHE9-XlnCMJzSxVSxUVGsw.png" /></figure><p>The object is of type “tag”:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/849/1*d_V0jezkF_XdLJNBTxhP9Q.png" /></figure><p>The <strong>tag </strong>object type contains the hash of the tagged object, the type of tagged object (usually a commit), the tag name, author, date, and message:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/693/1*-YviHHDxEJ9woSq0lQtKTQ.png" /></figure><p>Notice that the “<strong>object</strong>” the tag points to, via its hash, is the commit object, as were expecting.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/1*cEcA-Yz2NKdJlxWytCwjFw.png" /></figure><p>Now, we’ll do another commit, this time let’s say we made some changes to our index.txt file and committed those changes:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/690/1*3aZhgxeFY1F-IHcnUIeb0w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/799/1*xIedEB6XX6qXpLof6qhaEw.png" /><figcaption>Git creates a new blob object for the file that has changed.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/674/1*zuUjwCIQt_-iMRjfRq2f5Q.png" /></figure><p>As we see, git has now created 3 new objects for the second commit. Blob object with a new snapshot of the index.txt . Since README.md hasn’t changed, no new blob object for it is created, git will reuse the existing one instead (we’ll see in a second how).</p><p>Now, When git creates a tree object, blob pointer assigned to index.txt is updated and blob pointer assigned to README.md simply stays the same as in the previous commit’s tree.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/813/1*9xi3eFLVbSVxrXJzUIWnmQ.png" /><figcaption>Pointer to index.txt blob is updated and a pointer to README.md blob stays the same</figcaption></figure><p>And at the end, git creates a commit object with a pointer to its tree object.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/801/1*chgeUDpRD__eudPk3R45EQ.png" /><figcaption>Commit object points to its tree and also has a pointer to its parent commit object</figcaption></figure><p>and every commit expects that the first one has at least one parent.</p><p>I hope you find this helpful. If you liked it then don’t forget to give 👏 and share it with your friends.</p><p>Thank you, <em>Readers</em>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6009c271ca66" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mindorks/what-is-git-object-model-6009c271ca66">What is Git Object Model</a> was originally published in <a href="https://medium.com/mindorks">MindOrks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is git commit, push, pull, log, aliases, fetch, config & clone]]></title>
            <link>https://medium.com/mindorks/what-is-git-commit-push-pull-log-aliases-fetch-config-clone-56bc52a3601c?source=rss-e6f25903ed6c------2</link>
            <guid isPermaLink="false">https://medium.com/p/56bc52a3601c</guid>
            <category><![CDATA[commit]]></category>
            <category><![CDATA[fetch]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[push]]></category>
            <category><![CDATA[git]]></category>
            <dc:creator><![CDATA[Amit Prajapati]]></dc:creator>
            <pubDate>Fri, 20 Sep 2019 10:51:49 GMT</pubDate>
            <atom:updated>2019-11-17T15:42:21.048Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/990/1*_UUaozFPd2qHfCFjlhIgGA.png" /></figure><p><strong>Git </strong>is a powerful tool, but it has a reputation of baffling newcomers. It’s doesn’t help that most people are simply thrown in at the deep end and expected to swim.</p><p>With the right knowledge, anyone can master it. Once you start to understand it, the terminology will make more sense and you’ll (eventually) learn to love it.</p><h3>Why another guide?</h3><p>There are plenty of “git tutorials” out there already, but most of them simply tell you to copy/paste specific things to do one-off tasks. Anyone with a keyboard can copy/paste, to really understand how git works and what it can do for you, you need a slightly deeper understanding. If you want to know about Git, I have already written a blog so have a look at the below link.</p><p>Let’s start, <a href="https://medium.com/@pamit2897/introduction-to-git-e9d93a4ebd3"><strong>Git </strong></a>is a<em> version control system (software)</em> and <a href="https://medium.com/@pamit2897/introduction-to-git-e9d93a4ebd3"><strong>GitHub </strong></a>is a <em>source code hosting service</em>. Git is a version control system for tracking changes in computer files and coordinating work on those files among multiple people.</p><p>Lets Now, Understand the working of <strong>Git</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1018/1*E4povWZ5H-K3OaguFQJ0IQ.png" /></figure><p>A file in git goes through the following stages:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*5CeVAJMbE2udJbgDoALFIg.png" /></figure><h3>The Working Tree</h3><p>The Working Tree is the area where you are currently working. It is where your files live. This area is also known as the “<strong><em>untracked</em></strong>” area of git. Any changes to files will be marked and seen in the Working Tree. Here if you make changes and do not explicitly save them to git, you will lose the changes made to your files. This loss of change occurs because git is not aware of the files or changes in the Working Tree until you tell it to pay attention to them. If you make changes to files in your working tree git will recognize that are modified, but until you tell git “Hey pay attention to these files,” it won’t save anything that goes on in them.</p><p>How can you see what is in your Working Tree? Run the command <strong><em>git status. </em></strong>This command will show you two things: The files in your Working Tree and the files in your Staging Area. It will look like something in the image below if you don’t have anything in your Staging Area.</p><p>e.g: Let’s create two text files in a folder of any drive, and add some content to it and try to execute the git status command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/551/1*XtLTKDBEX9wlkLGXW2pP1Q.png" /><figcaption>Image of the Working Tree</figcaption></figure><p>So, First, you need to run <strong><em>git init</em></strong> command, because it will create a new git repository and then after you can perform <strong><em>git status the </em></strong>command to check to your in Working Tree. You can see that the <em>untracked files </em>are shown in red color. If you don’t run the git init command you will get an error, which looks like something in the image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/522/1*-1Jvo4REdi0WfHRoNageRQ.png" /></figure><p>So, It’s necessary to initialize our project with git. To run git commands.</p><h3>The Staging Area ( Index ):</h3><p>The Staging Area is when git starts tracking and saving changes that occur in files. The saved changes reflect in the .git directory. That is about it when it comes to the Staging Area. You tell git that I want to track these specific files, then git says okay and moves them from you Working Tree to Staging Area and says “Cool, I know about this file in its entirety.” However, if you make any more additional changes after adding a file to the Staging Area, git will not know about those specific changes until you tell it to see them. You <strong>explicitly </strong>have to tell git to notice the edits in your files.</p><p>How can you see what is in your Staging Area? Run the command <strong><em>git status </em></strong>like before. It will look something like the image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/604/1*IAxuNP6gYpO5u4IU1k2Gpw.png" /><figcaption>Image showing the Working Tree (red) and Staging Area (green)</figcaption></figure><p>How do you add files to your Staging Area? Running the command <strong><em>git add [filename] </em></strong>will add a specific file to the Staging Area from your Working Tree. If you want to add everything from the Working Tree, then run the command <strong><em>git add . </em></strong>The dot (.) operator is a wildcard meaning all files.</p><p><strong>git add . </strong>: Stages new and modified files, without deleting.</p><p><strong>git add -a </strong>: Stages all files.</p><p><strong>git add -u</strong> : Stages modified and deleted, without new.</p><p>Suppose, you modified a file that is not yet staged but after some time you think to revert the changes of a modified file. How do you do? There is a command in git is :</p><pre><strong>git checkout</strong> <em>file-name</em></pre><p>To remove the file from the staging area the command is :</p><pre><strong>git rm</strong> <strong><em>--cached</em></strong> <em>file-name</em></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*42depsg6vvOQVmBwxaTseg.jpeg" /><figcaption>Added the file in the staging area.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/967/1*NyApoe2ed-qj_pC3N0Y3BQ.jpeg" /><figcaption>Unstaged the file from the staging area.</figcaption></figure><h3>The Local Repository:</h3><p>The Local Repository is everything in your <strong>.git</strong> directory. Mainly what you will see in your Local Repository are all of your checkpoints or commits. It is the area that saves everything (so don’t delete it). That’s it.</p><p>How do you add items from your Staging Area to your Local Repository? The git command is <strong>git commit -m “</strong><strong><em>commit message</em></strong><strong>”</strong> taking all the changes in the Staging Area, wraps them together and puts them in your Local Repository. A commit is simply a checkpoint telling git to track all changes that have occurred up to this point using our last commit as a comparison. After committing, your Staging Area will be empty.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/523/1*LBB5S2s7NL5bKtNjl-pPsg.png" /></figure><h4>How is git commit command works internally?</h4><p>Let’s have a look at the working of git commit command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/642/1*EeAyiw_zUGDWZjTCe9z6ag.jpeg" /></figure><p>The above image shows the working of git commit command. In which the four blocks represent the commit with the unique <strong>SHA</strong> commit key. Suppose, you are on the <strong>master</strong> branch and you did a commit now git internally will create a block (node) of a commit you did. In git, we have a pointer called <strong>HEAD </strong><em>(It is the reference to the commit in the current branch in our case i.e master). </em>When you commit something the HEAD will be pointed to our commit in our case the commit hash key is <strong>b2e3 . </strong>If you made another commit now HEAD will move and point to commit having a hash key <strong>7d06</strong> means the parent of the <strong>7d06</strong> commit is <strong>b2e3</strong> because it holds the reference of the previous commit. As you see our last commit is <strong>9ba7 </strong>and the parent of this commit is <strong>3c09 </strong>and our HEAD is pointing to <strong>9ba7</strong> commit.</p><h4>Use of -a, -m or -am flags in git commit command</h4><ol><li><strong>git commit</strong> <strong>: </strong>The git commit command captures a snapshot of the projects currently staged changes. Committed snapshots can be thought of as “safe versions” of a project. Git will never change them unless you explicitly ask it to. Prior to the execution of git commit, The git add command is used to promote or “stage” commands git commit and git add are two of the most frequently used. The <em>git command</em> will launch a text editor prompting you for a commit message. After you’ve entered a message, save the file and close the editor, To close the editor type <strong>:wq </strong>to create the actual commit.</li><li><strong>git commit -a : </strong>Commit a snapshot of all changes in the working directory. This only includes modifications to tracked files ( those that have been added with <strong><em>git add</em></strong> at some point in their history).</li><li><strong>git commit -m </strong>“<em>commit message</em>” <strong>: </strong>A shortcut command that immediately creates a commit with a passed commit message. By default <strong>git commit</strong> will open up the locally configured text editor, and prompt for a commit message to be entered. Passing the <strong>-m</strong> option will forgo the text editor prompt in favor of an inline message.</li><li><strong>git commit -am</strong> <em>“commit message”</em> : A power user shortcut command that combines the <strong>-a</strong> and <strong>-m</strong> options. This combination immediately creates a commit of all the staged changes and takes an inline commit message.</li></ol><h4>Amend your last commit</h4><p>Git has a number of awesome features; Not least of all is the ability to amend the previous commit. If you ever find that you accidentally left something out of your last commit, be it a file or an extra change to a file that you just committed, don’t worry. It can easily be fixed.</p><p><em>for e.g</em>: This is what our working tree (directory) looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/832/1*se4bW0vbOCX9Twmz1_UK_A.jpeg" /></figure><p>Let’s make modifications in the “index.txt” file and after you add the file to the staging area and commit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/872/1*R37SacIjssollhopoXL1UA.jpeg" /></figure><p>After some time you realized that you made a mistake in the “<strong>index</strong>.<strong>txt</strong>” file. Now, what you will do? As usual, you correct the mistakes and commit the file it will another commit when you view using <strong>git log</strong> command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/872/1*9r32wkIqAxFaw1rxGr6yRA.jpeg" /></figure><p>As you see, we make another commit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/862/1*Y5b8P4e3SQIhKOfbQTXzNA.jpeg" /></figure><p>When viewing the commit history you can see we have two commits which is a bit confusing for the other developer when working with complex projects. So, here comes the <strong>git commit</strong> <em>--amend</em> command.</p><p>Let’s say, you again modify the file then add to the staging and commit it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/872/1*XeFALPqIYuExnrI3pCQYOg.jpeg" /></figure><p>The command <strong>git commit</strong> <em>--amend</em> <em>-m</em> “<em>commit-msg</em>” where <strong>-m </strong>is a flag used for the commit message. Let’s have a view of our commit history.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1004/1*I-om68treH56oHubWy34ZQ.jpeg" /></figure><p>As you see, <strong>amend </strong>command doesn’t create another commit history is just overrides the previous commit. So, that’s the use of <strong>git commit <em>--amend</em>.</strong></p><h4>Revert commit changes.</h4><p>If you want to revert a commit you have made you have to use :</p><p><strong>git reset --hard HEAD^</strong> command it will only revert the top commit means the latest commit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LdbOyuSOVfEqjNWkPksNGQ.jpeg" /></figure><p><em>For e.g. In the image above, you can see the latest commit as “</em><strong><em>added more courses</em></strong><em>” but we want to revert this commit. See in the image below.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*76bZb27NhNK2JEe70ziGkA.jpeg" /></figure><p>As you see, the pointer means the <strong>HEAD </strong><em>(It is the</em> reference <em>to the last commit in the currently check-out branch.)</em>is pointing to another commit now. i.e the <strong><em>“added more courses”</em></strong> commit is reverted back.</p><p>We have another command same as <strong>git reset</strong> <em>--hard</em> <strong>HEAD^</strong> called <strong>git reset</strong> <em>--soft</em> <strong>HEAD^ </strong>but in this command, we have used <strong>--soft</strong> option means it will reset the commit but don’t reset the content in that commit file.</p><p>for e.g: This is what your working tree (directory) looks like.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/832/1*se4bW0vbOCX9Twmz1_UK_A.jpeg" /></figure><p>Let’s make some modifications to the “<strong>login.txt</strong>” file. Firstly, let’s see the contents of the login.txt file using <strong>git show</strong> <em>:file-name</em> command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/654/1*duCjyAAXGO5XsTlE90U_vw.jpeg" /></figure><p>After that, you will add the file in the staging area and commit it.</p><p>Now, to view the commit history use the command <strong>git log</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/799/1*pakZV5bfovaBURqZIbh4Yg.jpeg" /></figure><p>Imagine a situation, where your teammates say why you commit the “<strong><em>login.txt</em></strong>” file it’s under processing. Now, what will you do? You have learned about <strong>git reset</strong> <em>--hard</em><strong> HEAD^</strong> to revert the commit, but the problem with this command is it will revert the commit with the file contents. But, in this scenario, we don’t want to revert the contents of the file. So, here comes the <strong>git reset</strong> <em>--soft</em> <strong>HEAD^</strong> command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/849/1*q0K4b_RBb0_UnbPUKfrp5Q.jpeg" /><figcaption>Commit revert successfully.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/688/1*07Q5Gud38iqftFW2daYRNg.jpeg" /></figure><p>As you see, the “login.txt” file contents were not reverted.</p><h3>Understanding Git Log</h3><p>Git logs allow you to review and read a history of everything that happens to a repository. The history is built using <strong>git log</strong> a simple tool with a ton of options for displaying commit history. A Git log is a running record of commits. A full log has the following pieces:</p><ul><li>A commit hash <strong>(SHA1 40 character checksum of the commit contents)</strong>. Because it is generated based on the commit contents it is unique.</li><li><strong><em>Commit Author metadata</em></strong>: The name and email address of the author of the commit.</li><li><strong><em>Commit Date metadata</em></strong>: A date timestamp for the time of the commit.</li><li><strong><em>Commit title/message</em></strong>: The overview of the commit as written in the commit message.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/505/1*v6W0XBn9166InmLBKHBjLA.png" /></figure><p>This is a snippet of the log, showing one commit. We have a commit <strong>SHA1 </strong>hash, the author, the date, and the commit message, explaining what happened in the commit. This layout is the default look of the log.</p><p>Git has something called Commit Limiting to make it easier to narrow down hundreds or thousands of commits to the ones you want to review.</p><p>Git is using SHA-1 hash in order to check files, the probability of having a hash conflict is near zero. So have fun !!</p><h4>Git Log Flags</h4><p>You can customize the information presented by <strong>git log</strong> using flags.</p><p>The <strong>--oneline </strong>flag causes <strong>git log</strong> to display :</p><ul><li>one commit per line.</li><li>the first seven characters of the SHA.</li><li>the commit message.</li></ul><pre><strong>git log</strong> <em>--oneline</em></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/919/1*RIilzZXPrEJa_IX8QVSL5A.jpeg" /></figure><p>The <strong>--stat </strong>flag causes <strong>git log</strong> to display :</p><ul><li>the files that were modified in each commit.</li><li>the number of lines added or removed.</li><li>a summary line with the total number of files and lines changed.</li></ul><pre><strong>git log</strong> <em>--stat</em></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/861/1*PVcSnNHpnnAmFuNZQINGdg.jpeg" /></figure><p>The <strong>--patch</strong> or <strong>-p</strong> flag causes git log to display :</p><ul><li>the files that you modified.</li><li>the location of the lines that you added or removed.</li><li>the specific changes that you made.</li></ul><pre><strong>git log</strong> <em>--patch</em>  or   <strong>git log</strong> <em>-p  or  git log -p -1</em></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/927/1*pJ4--blXPISw6FVGZhipGA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/845/1*-ouIllRN4BgiS9fKtuSFQA.jpeg" /></figure><p>In <strong>git log -p -1</strong>, where <strong>-1</strong> means to show only one commit detail you can write <strong>-2</strong> or <strong>-3</strong> as per your requirement.</p><h4>View a specified number of commits by author</h4><p>To start <strong>git log</strong> at a specific commit, add the SHA :</p><pre><strong>git log</strong> |<em>7752b22| -&gt; </em><strong><em>adeed jsut random SHA</em></strong></pre><p>This will display the commit with the SHA <em>7752b22 </em>and all of the commits made before that commit. You can combine this with any of the flags.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/885/1*W3NRCckgTu-3oIJC6JCtmQ.jpeg" /></figure><p>The <strong>--graph </strong>flag enables you to view yours <strong>git log</strong> as a graph. To make things interesting, you can combine this command with <strong>--oneline</strong> option you learned from above.</p><pre><strong>git log</strong> <em>--graph --oneline  </em><strong><em>or</em></strong><em>   </em><strong>git log</strong><em> --graph --decorate</em></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/924/1*ALgrJsefJzPGp553z2CGTg.jpeg" /></figure><p>One of the benefits of using this command is that it enables you to get an overview of how commits have merged and how the git history was created.</p><p>There are many other options you could use in combination with <strong><em>--graph</em></strong>. Couple of them are <strong>--decorate</strong> and <strong>--all .</strong></p><h4>Directory Restricted Log :</h4><p>The default log is great for grabbing a quick look at what just happened in the repository. But it takes up a lot of space and you can only see a handful of commits at once.</p><p>When I’m developing a project, I sometimes only want to know what happened in a specific directory. Let’s say I’m working on some CSS and only want to know about changes in my CSS directory. I can get much more specific with the git log and restrict it only to a specific directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/539/1*DvuV16UP9CcVZzRReDyvoQ.png" /></figure><p>This will only return commits that had changed in the CSS directory.</p><h4>Log by branch :</h4><p>We can use a similar syntax as directory restrictions and build a log for just one branch. We only need to specify the branch we want to see.</p><pre><strong>git log</strong> &lt;<em>branch-name&gt;</em></pre><h3>Git Configuration</h3><p>The<strong> <em>git config</em></strong> command is a convenience function that is used to set Git configuration values on a global and local project level. These configuration levels correspond to the text file called <strong>.gitconfig . </strong>Executing the git config will modify a configuration text file. We’ll be covering common configuration settings like email, username, and editor. We’ll be discussing Git aliases, which allow you to create shortcuts for frequently used Git operations. Becoming familiar with <strong>git config </strong>and the various Git configuration settings will help you create a powerful, customized Git workflow.</p><p>The most basic use of git config is to invoke it with a configuration name, which will display the set value at that name. Configuration names are dot delimited strings composed of a ‘section’ and a ‘key’ based on their hierarchy. For example <strong><em>user.name</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/484/1*dxfZv1FMFiAPZeDllfxl_Q.png" /></figure><p>In this example, the name is a child property of the user configuration block. This will return the configured name if any, that Git will associate with locally created commits.</p><h4>git config levels and files</h4><p>Before we further discuss git config usage, let’s take a moment to cover configuration levels. The<strong> </strong><strong>git config </strong>command can accept arguments to specify which configuration level to operate on. The following configuration levels are available:</p><ul><li><strong>--local</strong></li></ul><p><em>By default, git config will write to a local level if no configuration option is passed. The local level configuration is applied to the context repository git config gets invoked in. Local configuration values are stored in a file that can be found in the repo’s .git directory: </em><strong><em>.git/config</em></strong></p><ul><li><strong>--global</strong></li></ul><p><em>The global level configuration is user-specific, meaning it is applied to an operating system user. Global configuration values are stored in a file that is located in a user’s home directory. ~/.gitconfig on UNIX systems and </em><strong><em>C:\Users\&lt;username&gt;\.gitconfig on windows.</em></strong></p><p>Thus the order of priority for configuration level is the local, global.</p><p><strong>Writing a value</strong></p><p>Expanding on what we already know about git config, let’s look at an example in which we write a value:</p><pre><strong>git config <em>--global</em> user.name </strong><em>“your_name”</em></pre><pre><strong>git config<em> --global</em> user.email </strong><em>“your_email@example.com”</em></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/514/1*h-EpxgW8BzYuiSSCzfpEFg.png" /></figure><p>This example writes the value<strong> thesparkler</strong> to the configuration name user.name. It uses the — global flag so this value is set for the current operating system user.</p><h3>Git Aliases</h3><p>You may be familiar with the concept of aliases from your operating system command-line; if not, they’re custom shortcuts that define which command will expand to longer or combined commands. Aliases save you the time and energy cost of typing frequently used commands. Git provides its own alias system. A common use case for Git aliases is shortening the commit command. Git aliases are stored in Git configuration files. This means you can use the git config command to configure aliases. Aliases can be created in a local or global scope. To better understand Git aliases let us create some examples.</p><pre><strong><em>git config</em></strong><em> --global alias.co ---&gt; </em><strong>checkout</strong></pre><pre><strong>git config</strong> --global alias.br ---&gt; <strong>branch</strong></pre><pre><strong>git config</strong> --global alias.ci ---&gt; <strong>commit</strong></pre><pre><strong>git config</strong> --global alias.st ---&gt; <strong>status</strong></pre><p>The previous code example creates globally stored shortcuts for common git commands. Creating the aliases will not modify the source commands. So git commit will still be available even though we now have the <strong>git ci</strong> alias. These aliases were created with the --global flag which means they will be stored in Git’s global operating system level configuration file. On Linux systems, the global config file is located in the User home directory at /.gitconfig. These demonstrate that the aliases are now equivalent to the source commands.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/745/1*lOy1cAE-7QBYD_dy998ADg.png" /></figure><p>As you see, I’ve used <strong>git st </strong>the command to see my project status. So that’s the beauty of using git aliases.</p><h3>git push</h3><p>The git push command is used to upload local repository content to a remote repository. Pushing is how you transfer commits from your local repository to a remote repository. It’s the counterpart to <strong>git fetch</strong> but whereas fetching imports commits to local branches, pushing exports commits to remote branches. Remote branches are configured using the <strong>git remote</strong> command. Pushing has the potential to overwrite changes, caution should be taken when pushing.</p><pre><strong>git push </strong><em>&lt;remote&gt; &lt;branch&gt;</em></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/551/1*XqgTOmW3uT2_YO-z8NnRhA.jpeg" /></figure><p>Push the specified branch to <strong>&lt;remote&gt;</strong>, along with all the necessary commits and internal objects. This creates a local branch in the destination repository. To prevent you from overwriting commits, Git won’t let you push when it results in a non-fast-forward merge in the destination repository.</p><pre><strong>git push</strong> <em>&lt;remote&gt; --force</em></pre><p>Same as the above command, but force the push even if it results in a non-fast-forward merge. Do not use <strong>--force</strong> flag unless you’re absolutely sure you know what you’re doing.</p><pre><strong>git push</strong> <em>&lt;remote&gt; --all</em></pre><p>Push all of your local branches to the specified remote.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/616/1*HJx_4MCxp0ghLWtTIjH9RQ.jpeg" /></figure><p>The above diagram shows what happen when your local master has progressed past the central repository’s master and you publish changes by running <strong>git push origin master</strong>. Notice how git push is essentially the same as running git merge master from inside the git repository.</p><p>After adding a feature, making changes or other tasks in the local repository, you may use the push command for uploading these changes to the remote repository (e.g GitHub) so other team members can see it and may update their project accordingly.</p><p>A simple example of using the push command can be:</p><pre><strong>git push origin master</strong></pre><p>Where <strong><em>origin </em></strong>is the remote repository name (the default name). You may replace it with your repository name that was assigned at the time of the creation of the repository.</p><p>Note: The <strong>git push -u</strong> the command is equivalent to -set-upstream. The <strong>-u flag</strong> is used to set origin as the upstream remote in your git config. As you push a branch successfully or up to date, it adds an upstream reference.</p><p>As you push the local branch with <strong>git push -u </strong>the option, that local branch is linked with the remote branch automatically. The advantage is, you may use git pull without any arguments.</p><p>This is followed by providing the branch name. I used a master that you may replace with your branch name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/591/1*BijsZAgXoYCePW_BAplYzQ.png" /></figure><p>As you see, we got an error because we don’t have a remote repository. So, first of all, lets us create a remote repository on the <strong>GitHub </strong>website with the name <em>git-tutorials. </em>This is empty at this stage.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z8Opkp0DhliVy14ljEmS2Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-ByBdjzGKW8MGNbi6fPavw.png" /></figure><p>With this, we have created our remote repository. GitHub also provides some basic git commands as you see in the image above and also with HTTPS and SSH protocol.</p><p>To add your project to GitHub, use the git remote add command on the terminal, in the directory your repository is stored at.</p><pre><strong>git remote add </strong><em>&lt;remote-name&gt;&lt;remote URL&gt;</em></pre><p>The git remote add command takes two arguments:</p><ul><li>A remote name, for example, “origin”</li><li>A remote URL, Which you will see in the image below.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oMH-LcxTVHiYnSZy62Zimg.png" /></figure><p>After that, you can run the git push command to push your code to the GitHub repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/716/1*tV3hGInB55l-0008vcRmEQ.png" /><figcaption>Successfully pushed to GitHub repo</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fUzLPIhg7Z1kpDdhZNWvlw.png" /></figure><p>Our project is successfully pushed to the GitHub repository.</p><h3>Git Pull</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/567/1*yTyBOeE4AX-5h1FYEktRpg.jpeg" /></figure><p>The git pull command is used to fetch and download content from a remote repository and immediately update the local repository to match the content. Merging remote upstream changes into your local repository is a common task in Git-based collaboration workflows. The <strong>git pull</strong> command is actually a combination of two other commands, git fetch followed by git merge. In the first stage of operation, git pull will execute a git fetch scoped to the local branch that <strong>HEAD </strong><em>( means the reference to the current commit) </em>is pointed at. Once the content is downloaded, git pull will enter a merge workflow. A new merge commit will be created and <strong>HEAD</strong> updated to point at the new commit.</p><p><em>For e.g:</em> If someone from your team made some changes in a file or created some file on a remote repository. Let’s say he/she created a file named as <strong>portfolio.txt </strong>but you don’t know what he/she changes on the remote repository. Let’s say you have created another file named as <strong>service.txt</strong>and that after you commit the file and when you try to push that file on your remote repository git will not allow you to push your code because the remote repository contains work that you do not have locally. So, In this case, the git pull command is used to fetch and download content from a remote repo to local repo.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EQtlixHRk_4IOmRrchvm6g.png" /><figcaption>creating a new file on the remote repository</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9WS7rtBJzSCqbDT9AwUw-Q.png" /><figcaption>Edited portfolio.txt file</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rxWCmf9hn_WDBOrebpKhlg.png" /><figcaption>Added commit message and click in commit new file to save changes</figcaption></figure><p>Now, you’ll create another file in the local repository (in your system).</p><p>After creating the <strong>“<em>service.txt”</em></strong> file you will add the file to staging area using <strong>git add </strong><strong><em>“</em></strong><em>service.txt</em><strong><em>”</em> </strong>command after that you will commit that file using <strong>git commit -m </strong><em>“added service page” </em>command and after that, you will push that file on remote repository using git push origin master<strong> </strong>command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/919/1*JsIwRPvRYBIqOk2IERwVPg.png" /></figure><p>In the above image, you see that we got an error while performing git push<strong> </strong>the command. Now, to solve this error new need to run git pull origin master command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/882/1*z6CP2S3N9y4o04Uzq569lQ.png" /></figure><p>In the above image, you see that your file is successfully pushed to the master branch because we use git pull origin master the command to up-to-date our local repository from a remote repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wbME5aTryn2gb0X74uHqdA.png" /></figure><h4>Note: About Merge Conflicts</h4><p>Merge conflicts happen when you merge branches that have competing commits, and Git needs your help to decide which changes to incorporate in the final merge.</p><p><em>Git can often resolve differences between branches and merge them automatically. Usually, the changes are on different lines, or even in different files, which makes the merge simple for computers to understand. However, sometimes there are competing changes that Git can’t resolve without your help. Often, merge conflicts happen when people make different changes to the same file, or when one person edits a file and another person deletes the same file. If you have a merge conflict on the command line, you cannot push your local changes to GitHub until you resolve the merge conflict locally on your computer.</em></p><p>To resolve merge conflicts run merge conflict resolution tools. The command is: <strong>git mergetool</strong></p><h3>Git Fetch</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/527/1*jAuExv9j5-2QedsaJYUcoA.jpeg" /></figure><p>When we use<strong> </strong><strong>git fetch</strong> the command we fetch the commits of a remote repository into our local repository. The fetched commits are saved as remote branches separate from the local branches. So, this helps in reviewing the commits before integrating them into the local working branches.</p><h4>Fetch branches</h4><p><em>For e.g.: let’s create a new file named </em><strong><em>“news.txt” </em></strong><em>in a different branch named </em><strong><em>‘newsBranch’.</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O_tzBUT3ID3jaXDSI77GfQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uxTcVyM10Rz0yM9lQAVdTg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pr9qtb7YcQ6b80DcxR9OJg.png" /></figure><p>Then after creating a pull request as you see in the above image. “<em>Now you might be thinking what is </em><strong><em>pull request</em></strong>”. So, Pull requests let you tell others about changes you’ve pushed to a branch in a repository on GitHub. Once a pull request is opened, you can discuss and review the potential changes with collaborators and add follow-up commits before your changes are merged in the base branch.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8VacenMulgBY1YyKCiUmqA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e_WTeEyEKKr1p2SNCdMHgQ.png" /></figure><p>In the above image, you can see the new branch is added named<strong> ‘newsBranch’.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IlDu2V3p7K7N-pXKWjRkMA.png" /><figcaption>newsBranch project view.</figcaption></figure><p>So, To work on “<strong><em>newsBranch</em></strong><em>”</em> we need to switch from the <em>master </em>branch to the “<strong><em>newsBranch”</em></strong><em> </em>branch. The command to switch branch is :</p><pre><strong><em>git checkout </em></strong><em>[branch-name]</em><strong><em>.</em></strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*S5nYyMywytU8icZ36LrLZg.png" /></figure><p>We got an error, says newsBranch doesn’t match any file doesn’t match any branch or doesn’t exist a branch like this but I cannot create a branch called newsBranch and then pull and push from my remote repository because that branch already exists. I cannot absolutely do that I need to fetch this branch before being able to work on it so in order to fetch the branch so let’s simply write git fetch origin and then git checkout newsBranch perfect so this was really easy because with the fetch origin we specify to the origin that is our git repository on GitHub to fetch all the branches that we currently gonna have on our local environment. If we wanted to fetch just a specific branch you can just specify<strong> </strong><strong>git fetch [</strong><em>remote-name</em><strong>][</strong><em>branch-name</em><strong>]. </strong>But if you just write git fetch origin, git is going to recognize automatically all the branches that you currently don’t have on your local git repository but our presence they exist on our remote repository so now we are on the git content and if we check in your system the news.txt file is there that we don’t have in our master branch.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/689/1*FwHtIlBkseppjM3hGJaP0A.png" /></figure><p>We use <strong>git fetch [</strong><em>remote-name</em><strong>] </strong>the command to fetch all the branches commits and files of the remote connection.</p><p><strong>View remote branches</strong></p><p>To view the remote branches that were fetched we use the <strong><em>git branch -r </em></strong>command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/593/1*iwBOL6jwjQlHdSUehENQUw.png" /></figure><p>As the fetched commits are saved as remote branches and not integrated into our local branches it gives an opportunity to review the changes and decide whether we want to merge the fetched changes in our local branches.</p><h4>Fetch and Merge</h4><p>Let say other developers have committed changes and pushed those changes to the central repository which then got merged to the master branch.</p><p>Now we want to fetch those changes from the master branch. So we will run the git fetch command.</p><pre><strong>git fetch</strong> <em>origin master</em></pre><p>So, we now have the <strong>origin/master</strong> branch with us as a remote branch and it is not yet merged into the master branch of our local repository.</p><p>After reviewing the changes in the remote branch we can merge it into our local branch using<strong> </strong><strong>git merge</strong> command.</p><pre><strong>git merge origin/newsBranch</strong></pre><blockquote><strong>Note</strong> : Local branch : master (on local system)</blockquote><blockquote><strong><em>Remote Tracking branch</em></strong> : origin/newsBranch (on local system)</blockquote><blockquote><strong><em>Remote branch</em></strong> : master (origin master on GitHub or remote server)</blockquote><blockquote><strong>git fetch</strong> : updates remote-tracking branch from remote branch</blockquote><blockquote>e.x : updates (origin/master) from (origin master)</blockquote><blockquote><strong>git merge</strong> : merges remote-tracking branch into local branch</blockquote><blockquote>e.x : merge (origin/master) into (master)</blockquote><h3>Git clone</h3><p>git clone is a Git command-line utility that is used to target an existing repository and create a clone, or copy of the target repository. The command for cloning the repository is :</p><pre><strong>git clone &lt;</strong><em>repository-link</em><strong>&gt;</strong></pre><p>for e.x. : Let’s say you want to clone the <strong><em>TensorFlow</em></strong><em> repository</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P0C2zt-gg4wgXaPpsfEWRQ.png" /></figure><p>In the above image, It’s a TensorFlow repository and we want to clone it means to download it in our system. We have to use the link to clone this repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/697/1*jJpxvq1rT-NFIQQni8qM1g.png" /><figcaption>cloning the repo</figcaption></figure><p>If you found this blog useful, please help by tapping the 👏 button as many times as you’d like so others can find it too. Clap is enough because I don’t drink coffee :D</p><p>Thank you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=56bc52a3601c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mindorks/what-is-git-commit-push-pull-log-aliases-fetch-config-clone-56bc52a3601c">What is git commit, push, pull, log, aliases, fetch, config &amp; clone</a> was originally published in <a href="https://medium.com/mindorks">MindOrks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is git stash & readme.md file.]]></title>
            <link>https://medium.com/mindorks/what-is-git-stash-readme-md-file-5c2be3e5b1e1?source=rss-e6f25903ed6c------2</link>
            <guid isPermaLink="false">https://medium.com/p/5c2be3e5b1e1</guid>
            <category><![CDATA[git-stash]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[readme]]></category>
            <category><![CDATA[git]]></category>
            <dc:creator><![CDATA[Amit Prajapati]]></dc:creator>
            <pubDate>Fri, 20 Sep 2019 10:50:56 GMT</pubDate>
            <atom:updated>2019-09-20T10:50:56.622Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/766/1*BEbIx5g11hzzL7RMCnXdiA.png" /></figure><p>In this blog, we will try to explore git commands like <strong><em>git stash </em></strong>and <strong><em>README.md</em></strong> file.</p><blockquote>Today’s Motivation</blockquote><blockquote>“A pessimist sees the difficulty in every opportunity; an optimist sees the opportunity in every difficulty.”</blockquote><p>So, Let’s get started… 🙂</p><h4>What is the use of git stash command?</h4><p>The git stash command temporarily shelves (or stashes) changes you’ve made to your working copy so you can work on something else, and then come back and re-apply them later on. Stashing is handy if you need to quickly switch context and work on something else, but you’re mid-way through a code change and aren’t quite ready to commit.</p><p>The git stash command takes your uncommitted changes (both staged and unstaged), saves them away for later use, and then reverts them from your working copy.</p><p><strong><em>for e.g</em></strong><em>. Let’s say, you start working in the portfolio.txt and about.txt file to add some functionality that is not yet completed to commit (means to save). Then suddenly, some of your fellow team members say that we have to show the project to the client now. Now, What will you do, you have made modifications in the portfolio.txt and about.txt file. You might be thinking let’s take the backup of the edited modifications, then why we are using git? If we want to take the backup of the code. So, here comes the </em><strong><em>git stash</em></strong><em> command to save your uncompleted work. Suppose, the modifications you made is just 10–30 lines of code which you can write again once deleted so the git command is </em><strong><em>git reset</em></strong><em> --hard . If not, then the </em><strong><em>git stash</em></strong><em> command comes into the picture.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/846/1*wR3MRTZ5rqQzOhY3RMBUUA.jpeg" /><figcaption>Tracked two changes files.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/867/1*Mla3MHhmCfTczc2mILVy6Q.jpeg" /><figcaption>You can see the changes in the file content.</figcaption></figure><h4>Git stash save</h4><p>The command is like Git stash. But this command comes with various options.</p><h4>Git stash with message</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/706/1*uHn8ToWUavOV7GkN1sjMIQ.jpeg" /></figure><p>In the above image, we stash both the files with a message so we can understand what changes I have done in these files.</p><p>To stash a particular file the command is :</p><pre><strong>git stash save</strong> <em>file-name</em></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/854/1*vaHQXWQtObVosu8A2uUzyA.jpeg" /></figure><p>In the beginning image, you might see the tracked files which are modified, the files are “<strong><em>about.txt</em></strong><em>”</em> and “<strong><em>portfolio.txt</em></strong>”. But after stash both the files, we perform the command git status which shows “<strong><em>nothing to commit, working tree clean</em></strong>” i.e. the modified file is not shown because it saves the file temporarily in the master branch and your modified file contents will be not displayed, the only display is your last commit contents.</p><h4>Git stash list</h4><p>Before discussing this command, let me tell you something about how stash works.</p><p>When you Git stash or Git stash save, Git will actually create a Git commit object with some name and then save it in your repo.</p><p>So it means you can view the list of stashes you made at any time.</p><pre><strong>git stash </strong><em>list</em></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/703/1*yNH2ssxoDJ6nrJvhB7JKyg.jpeg" /></figure><p>You can see the list of stash made. And the most recent stash will be at the top.</p><p>And you can see that the top stash is given a custom message that we did it earlier (using <strong>git stash save</strong> “<em>message</em>”).</p><h4>Git stash apply</h4><p>This command takes the top-most stash in the stack and applies it to the repo means whatever, we changed in the about.txt and the portfolio.txt file will come back. In our case, it is<strong><em> stash@{0}.</em></strong></p><p>If you want to apply some other stash you can specify the stash id.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/741/1*XwxcRyeBf6h4JR7ngRsiVA.jpeg" /></figure><p>But after applying, the stash will not be deleted automatically. So, to delete the stash we have a command called git stash pop.</p><h4>Git stash pop</h4><p>This command is very similar to stash apply but it deletes the stash from the stack after it is applied.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/1*VOIZhzz_zchy4E7_kzDPaQ.jpeg" /><figcaption>stash deleted.</figcaption></figure><p><strong><em>for e.g.</em></strong><em> Let’s say, you have multiple stashes. As you can see the top stash is deleted and </em><strong><em>‘stash@{0}’</em></strong><em> is updated with the older stash. Likewise, if you want a particular stash to pop you can specify the stash id.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*Mm-I9AfWTcp8ue3WMp8N7A.jpeg" /></figure><h4>Git stash show</h4><p>This command shows the summary of the stash diffs. If you want to see the full diff, you can use</p><pre><strong>git stash </strong><em>show -p</em></pre><p>Likewise, with other commands, you can also specify the stash id to get the diff summary.</p><pre><strong>git stash show</strong> <em>stash-id</em></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/739/1*N90A6DBbEPtu2TDhAc5-CQ.jpeg" /></figure><h4>Git stash clear</h4><p>This command deletes all the stashes made in the repo. It may be impossible to revert.</p><pre><strong>git stash clear</strong></pre><h4>Git stash drop</h4><p>This command deletes the latest stash from the stack. But use it with caution, it may be difficult to revert.</p><pre><strong>git stash drop</strong> stash-id</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*oTX8K2fqyznv7EmQg-VNoQ.jpeg" /></figure><p>If everything goes fine, you can commit the changes and push to the master branch.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/739/1*XF9G_YqKRfAY5RFKKSnZZQ.jpeg" /></figure><h4>What is the README file?</h4><p>A <strong><em>README (as the name suggests: “read me”)</em></strong><em> </em>file in a project<em> (including those projects hosted on GitHub) </em>is written by people <em>(project developers)</em> for the other people to read. It is, simply the “<em>front page</em>” of the project; the “place ” where everyone gets started.</p><p>It usually describes what kind of project it is, how it can be useful, how to install and use it — also, the list of authors, guidelines for contributing, license notice and whatever else the developers would want others, people, to read.</p><p>The<em> Open-source community</em> is growing rapidly. Developers release new open-source projects on <strong>GitHub</strong> every day. As a result, it’s becoming more and more difficult to get your own project to stand out from the sea of open-source software. However, you can do a few things to increase your chances of grabbing other’s developer’s attention. One effective and simple technique is <strong>putting up a nice-looking and helpful README file</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1014/1*zLqjOUVkJSvZx_lCH206Xw.png" /></figure><p>The .md extension means markdown. <strong>README.md</strong> is used to generate the <strong>Html</strong> summary you see at the bottom of the projects.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LPxe0g6NuJ8KQnG9W6KAWw.png" /></figure><p>Here you will write all the information that is commonly required to understand what the project is about.</p><h4>Let’s try to understand Markdown syntax Cheat Sheet.</h4><p><em>Markdown</em> is a way to style text on the web. You control the display of the document; formatting words as bold or italic, adding images and creating lists are just a few of the things we can do with Markdown. Mostly, Markdown is just regular text with a few non-alphabetic characters thrown in, like # or *.</p><p><strong>Headers</strong></p><ul><li>To write heading we have to use # symbol, we can use 1 to 6 level heading as we do in HTML</li></ul><pre><strong>#H1</strong></pre><pre><strong>##H2</strong></pre><pre><strong>###H3</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XCQHuF4QuSyG7mgYnK8KGg.jpeg" /><figcaption>You can see the changes in the <strong>Preview changes </strong>view</figcaption></figure><p><strong>Text Styling</strong></p><pre>Common text</pre><pre>_Emphasized text_ or *Emphasized text*</pre><pre>~~Strikethrough text~~</pre><pre>__Strong  text__ or **Strong text**</pre><pre>___Strong emphasized text___ or ***Strong emphasized text***</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/524/1*O0IDdLyq3gfp7wogRM9n6g.png" /></figure><p><strong>Links</strong></p><p>To add links use square brackets [] followed by a pair of parentheses (). In the square brackets, we actually write what is going to be the link on which people gonna click. In the round brackets, we provide the link.</p><pre><strong>[Visit Google website](</strong><a href="https://google.com/"><strong>https://google.com</strong></a><strong> “Google”)</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/207/1*B8hI6VugOOnR8InraVqp0w.png" /></figure><p><strong>Images</strong></p><p>There are two ways you can add an image to your GitHub repository.</p><p><strong><em>First way: </em></strong>In the first way we have to open an issue then drag and drop the image you want. Then after it will generate the image URL.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mXutHhpVKu8FO_ZzkVDfmA.jpeg" /><figcaption>Click on the Issues section</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3h4FtHeSjzDfD8haKoGbog.jpeg" /><figcaption>Create a new issue</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J_nkbIuwel-T8sAxbMbjuQ.jpeg" /></figure><p>So, here we get our image path and now we will copy this image path and paste in the src attribute of &lt;img/&gt; in the README file.</p><pre>&lt;img src=”<a href="https://user-images.githubusercontent.com/41661723/61168740-4c81b580-a570-11e9-8710-0e6b665860a4.png">https://user-images.githubusercontent.com/41661723/61168740-4c81b580-a570-11e9-8710-0e6b665860a4.png</a>&quot; width=”50&quot; height=”50&quot;/&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CgrA1KmupSSgiOFvYAVpOQ.png" /></figure><p><strong><em>Second way: </em></strong><em>W</em>e have to use the syntax. ![img-name](img-path)</p><pre>![git](<a href="https://user-images.githubusercontent.com/41661723/61168740-4c81b580-a570-11e9-8710-0e6b665860a4.png">https://user-images.githubusercontent.com/41661723/61168740-4c81b580-a570-11e9-8710-0e6b665860a4.png</a> &quot;GIT&quot;)</pre><p><strong>Fenced Code Blocks</strong></p><p>The basic Markdown syntax allows you to create code block by indenting lines by four spaces or tab. If you find that inconvenient, try using fenced code blocks. Depending on your Markdown processor or editor, you’ll use three tick marks ( ```) or three tildes (~~~) on the lines before and after the code block. The best part? You don’t have to indent any lines!</p><pre>```<br>{<br>   &quot;firstName&quot;: &quot;John&quot;,<br>   &quot;lastName&quot;:  &quot;Smith&quot;,<br>   &quot;age&quot;: 25<br>}<br>```</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/251/1*PkTUaq73AkbqRwkN7SXhNQ.png" /></figure><p><strong>Syntax Highlighting</strong></p><p>Many Markdown processors support syntax highlighting for fenced code blocks. This feature allows you to add color highlighting for whatever language your code is written in. To add syntax highlighting, specify a language next to the tick marks before the fenced code block.</p><pre>```javascript<br>var name = &quot;Amit&quot;<br>console.log(name)<br>```</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/267/1*awE2WuXAU8DBGRvyal87tw.png" /></figure><p><strong>Tables</strong></p><p>To add a table, use three or more hyphens ( — -) to create each column’s header, and use pipes (|) to separate each column. You can optionally add pipes on either end of the table.</p><pre>| Syntax | Description |<br>| ------ | ----------- |<br>| Header | Title       |<br>| paragraph | Text     |</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/302/1*Tub3ODF-svnDkNWsifJgow.png" /></figure><p><strong>Alignment</strong></p><p>You can align text in the columns to the left, right, or center by adding a colon (:) to the left, right, or on both sides of the hyphens within the header row.</p><pre>|Syntax|Description|Test Text|<br>|:---  |  :----:   |  ---:   |<br>|Header | Title    |Here&#39;s this|<br>|Paragraph | Text  |And more   |</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/441/1*RM2DD5tk1nA2IvKbHRvjPw.png" /></figure><p><strong>Blockquotes</strong></p><p>You can create blockquote with greater than symbol ( &gt; ). If you want nested blockquote use (&gt;&gt;)</p><pre>&gt; Keep smiling and work harder.<br>&gt;&gt; Peace</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/438/1*cJMKDGBjxqh-HUVnKlf1tg.png" /></figure><p><strong>Horizontal Rule</strong></p><pre>Three or more...</pre><pre>--- <br>Hyphens</pre><pre>***  <br>Asterisks</pre><pre>___   <br>Underscores</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/938/1*_ZAg6fIkSDRz1Zy5bcZh-w.png" /></figure><p><strong>Lists</strong></p><p><strong>1) Bullet List</strong></p><pre>* Bullet list<br>    * Nested bullet<br>        * Sub-nested bullet etc<br>* Bullet list item 2</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/393/1*xyMQLdcQEY_-lW_ef3SgDg.png" /><figcaption>Output</figcaption></figure><p><strong>2) Numbered list</strong></p><pre>1. A numbered list<br>     1. A nested numbered list<br>     2. Which is numbered<br>2. Which is numbered</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/440/1*QF4N1qdW1yIPoOSI7X-WuA.png" /></figure><p><strong>Checkbox</strong></p><pre>- [ ] An uncompleted task<br>- [x] A completed task</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/288/1*bdcZaplHXLu0x5L1EnsJGg.png" /></figure><p>After adding all the information about your project. Now, you can commit the changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wghQBHa783OJQaomWErMJw.jpeg" /></figure><p>After committing your README file will be added to your project.</p><p>I hope you got some useful knowledge about the Git stash and README file.</p><p>If you enjoyed the blog, give me clap 👏 and share it :)</p><p>Thank you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5c2be3e5b1e1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mindorks/what-is-git-stash-readme-md-file-5c2be3e5b1e1">What is git stash &amp; readme.md file.</a> was originally published in <a href="https://medium.com/mindorks">MindOrks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is git cherry-pick & .gitignore file]]></title>
            <link>https://medium.com/mindorks/what-is-git-cherry-pick-gitignore-file-482b446e3973?source=rss-e6f25903ed6c------2</link>
            <guid isPermaLink="false">https://medium.com/p/482b446e3973</guid>
            <category><![CDATA[github]]></category>
            <category><![CDATA[cherry-picking]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[git]]></category>
            <category><![CDATA[gitignore]]></category>
            <dc:creator><![CDATA[Amit Prajapati]]></dc:creator>
            <pubDate>Fri, 20 Sep 2019 10:50:41 GMT</pubDate>
            <atom:updated>2019-09-20T10:50:41.691Z</atom:updated>
            <content:encoded><![CDATA[<h3>What is git cherry-pick &amp; .gitignore file</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/830/1*9vCP3LQn7irlPLaJQcBuDA.jpeg" /></figure><p>In this blog, we will understand the git commands like <strong>.gitignore </strong>and <strong>git cherry-pick.</strong></p><blockquote>Today’s Motivation</blockquote><blockquote>“You must find the place inside yourself where nothing is impossible.”</blockquote><p>So, Let’s get started… 👩‍💻</p><h4>What is the use of git ignore file?</h4><p>Sometimes, our project not only consists of the code that we created. There are some files that are generated by our IDE or our framework that aren’t actually needed. These files or folders sometimes also may generate errors when copied to other PC, so that’s why we need to ignore those unnecessary files or folders.</p><p>Ignored files are usually build artifacts and machine-generated files that can be derived from your repository source or should otherwise not be committed. Some common examples are:</p><ul><li>dependency caches, such as contents of <strong>/node_modules </strong>or <strong>/packages</strong></li><li>compiled code, such as <strong>.o</strong>, <strong>.pyc</strong>, and <strong>.class</strong> files</li><li>build output directories, such as <strong>/bin</strong>, <strong>/out</strong>, or <strong>/target</strong></li><li>files generated at runtime, such as <strong>.log</strong>, <strong>.lock</strong>, or <strong>.tmp</strong></li><li>hidden system files, such as <strong>.DS_Store</strong> or <strong>Thumbs.db</strong></li><li>personal IDE config files, such as <strong>.idea/workspace.xml</strong></li></ul><p>To know more about which file you can ignore in your project click on the below link. 👇</p><p><a href="https://github.com/github/gitignore">GitHub - github/gitignore: A collection of useful .gitignore templates</a></p><p>The entries in this file can also follow a matching pattern.</p><ul><li><strong>*</strong> is used as a wildcard match.</li><li><strong>/</strong> is used to ignore pathnames relative to the .gitignore file</li><li><strong>#</strong> is used to add comments to a .gitignore file</li></ul><p>This is an example of how our .gitignore file will look like:</p><pre># Ignore Mac system files<br>  <strong>.DS_Store</strong></pre><pre># Ignore node_modules folder<br>  <strong>node_modules</strong></pre><pre># Ignore all text files<br>  <strong>.txt</strong></pre><pre># Ignore files related to API keys<br> <strong> .env</strong></pre><pre># Ignore folder named &#39;output&#39;<br>  <strong>output/</strong></pre><p>This is the image of our remote repository. 👇</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*59FAu7hczyBvxDcR19LNXg.jpeg" /><figcaption>Remote Repository</figcaption></figure><p>Let’s have a look at our local repository as well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YCALdVJuXQIqWFJxX4OlMw.jpeg" /><figcaption>Local Repository</figcaption></figure><p>The command <strong>dir</strong> is used to view the files and directories of your working directory.</p><p>The command <strong>ls -a</strong> is used to view the hidden files such as <strong>.git </strong>and <strong>.gitignore</strong> files are present.</p><p><strong><em>for e.g</em></strong><em>: Let’s say, you create another file named ‘</em><strong><em>payment.txt</em></strong><em>’ but you didn’t want git to track this file. So, you can put this file in the </em><strong><em>.gitignore</em></strong><em> file. We use the touch command to create this file.</em></p><pre><strong>touch </strong><em>.gitiginore</em></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fpmcXVyTrG0EhoJ_kYzbvw.jpeg" /></figure><p>In the above image, you can see the .gitignore file and payment.txt file are there. Now, let’s try to run the <strong>git status</strong> command and see what happens?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tHZJRmZwdvpTmBUpoWqRAA.jpeg" /></figure><p>As you see in the above image, git doesn’t track <strong>“payment.txt”</strong> because it’s under <strong>.gitignore</strong> file. Git ignores the files which are present in the .gitignore file after that you will add the .gitignore file to the staging area and you commit and push it to GitHub, but you won’t able to see the payment.txt file in your remote repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lPCPHIiYgNB_m0r6UjrFrw.jpeg" /></figure><p>Now, let’s have a look at our remote repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GJhmyZ_dUaiuntv9CEKz3g.jpeg" /></figure><p>In the above image, you see the <strong>.gitignore</strong> file is added but <strong>“payment.txt”</strong> is not. Now, let’s have a look at what’s inside <strong>.gitignore</strong> file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2vEf2o1zw7giyFJ5kPrEgQ.jpeg" /></figure><p>Inside the<strong> .gitignore file</strong>, we added the name of the file which wants to ignore in our case, it is the<strong> “payment.txt”.</strong></p><h4>What is git cherry-pick?</h4><p>When you are working with a team of developers on a medium to a large-sized project, managing the changes between the number of git branches can become a complex task. Sometimes you don’t want to merge a whole branch into another, and only need to pick one or two specific commits. This process is called ‘<strong><em>cherry-picking</em></strong>’.</p><p>What git cherry-pick does, basically, is take a commit from somewhere else, and “play it back” wherever you are right now. Because this introduces the same change with a different parent, Git builds a new commit with a different ID.</p><p>Let’s look at this example.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/334/1*u0E2FUKOlzQOWesCBIBVqw.jpeg" /></figure><p>If you were at node H in this graph, and you typed <strong>git cherry-pick E</strong> (yes, you’d actually type part or all of the SHA (Secure Hash Algorithm) or hash key) for the commit, but for simplicity’s sake, I’ll just use the labels that are already here), you’d wind up with a copy of commit E — let’s call it “E prime” or <strong>E’ </strong>— that pointed to <strong>H </strong>as its parent, like so:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/335/1*VMu_o22URw_6i_1Xh3NyCw.jpeg" /></figure><p>Or, if you typed something like <strong>git cherry-pick C D E </strong>, you’d wind up with this when you were done.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/455/1*6YUPPY_pKUlGN6kp476Dww.jpeg" /></figure><p>The important thing to notice here is that Git has copied changes made in one place, and replayed them somewhere else.</p><h4>When should we use Cherry Picking?</h4><p>I will try to explain this through a scenario that will make it easier to understand.</p><p><strong><em>for e.g</em></strong>: <em>Let’s create a new branch called </em><strong><em>new-features</em></strong><em>.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PXySIfsUn1NmCj2wRCObwQ.jpeg" /></figure><p>Let’s say you are working on the <strong>new-features</strong> branch and you made some changes in the file called <em>courses.txt</em> and commit it and push it into the <strong>new-features</strong> branch.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*95MFSQ-W26HmcsqX1nYmaA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_N1QCGhQ0tpVXzm4gk81sA.jpeg" /></figure><p>Here, we made some changes to the courses.txt and push it on the <strong>new-features</strong> branch. Now, you have already made changes in the<em> courses.txt</em> but you want to move the <strong><em>courses.txt</em></strong> file changes into the <strong>master</strong> branch. We can do with the help of <strong>git merge</strong> command, but we don’t want to merge the whole <strong>new-features</strong> branch in it. We just want the specific commit which was performed in the courses.txt and add this commit on the <strong>master</strong> branch.</p><p>From the “<strong><em>new-features</em></strong>” branch run <strong>git log</strong> <em>--oneline </em>to get a better log of our commits history. Note that the commit hash is what we need to start the cherry-picking.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*unEsD80178qQVQyShrS7PA.jpeg" /><figcaption>List of commits performed in the <strong>new-features</strong> branch.</figcaption></figure><p>Now, check-out the branch where you want to cherry-pick the specific commits. In this case <strong>master</strong> branch.</p><pre><strong>git checkout master</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PkyRU56ZNeCdQfY-Q5z6Qg.jpeg" /></figure><p>The above image shows that we need to checkout to the <strong>master</strong> branch then perform <strong>git log --oneline</strong> command to display the commits in the <strong>master</strong> branch.</p><p>Now we can cherry-pick from <strong>new-features</strong> branch:</p><pre><strong>git cherry-pick</strong> <em>commit-id</em></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gzQ-lRNzGj6KLcEGlxYYlw.jpeg" /></figure><p>This will cherry-pick the commit with hash <strong>‘d545959’ </strong>and add it as a new commit on the master branch.</p><p><strong><em>Note</em></strong>:<em> It will have a new (and different) commit ID in the master branch.</em></p><p>If you want to <strong><em>cherry-pick</em></strong> more than one commit in one go, you can add their commit IDs separated by a space.</p><p>e.g. <strong>git cherry-pick</strong> <strong><em>d467740 de906d4</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fPvosQB9vAWRkXT5T-eLUg.jpeg" /></figure><p>As you see in the image above, we successfully added the <strong>new-features </strong>commit in the <strong>master </strong>branch.</p><p>If the cherry-picking gets halted because of conflicts, resolve them and <strong>git cherry-pick</strong> <em>--continue</em></p><ul><li><strong>--continue</strong>: This can be used to <em>continue</em> after resolving conflicts in a failed cherry-pick or revert.</li></ul><p>If you want to bail off this step out altogether, just type: <strong>git cherry-pick</strong> <em>--abort</em></p><ul><li><strong>--abort : </strong>Cancel the operation and return to the pre-sequence state.</li></ul><p>After all, this is done, you can simply push the new commits to the upstream repo (e.g. origin) and get on with your day.</p><p>Hopefully, this blog should have helped you in understanding the .gitignore file and git cherry-pick command.</p><p>If you really enjoyed reading this blog, give me a clap and share it :-)</p><p>Thank you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=482b446e3973" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mindorks/what-is-git-cherry-pick-gitignore-file-482b446e3973">What is git cherry-pick &amp; .gitignore file</a> was originally published in <a href="https://medium.com/mindorks">MindOrks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is git diff & git branch]]></title>
            <link>https://medium.com/mindorks/what-is-git-diff-git-branch-4bd9890d68b0?source=rss-e6f25903ed6c------2</link>
            <guid isPermaLink="false">https://medium.com/p/4bd9890d68b0</guid>
            <category><![CDATA[branch]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[git-diff]]></category>
            <category><![CDATA[git]]></category>
            <dc:creator><![CDATA[Amit Prajapati]]></dc:creator>
            <pubDate>Wed, 18 Sep 2019 18:49:28 GMT</pubDate>
            <atom:updated>2019-09-18T18:49:28.117Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8p5liiPXxjj3BExWlwAkLA.jpeg" /></figure><p>In this blog, we will try to understand the most important commands i.e git diff and git branch.</p><blockquote>Today’s motivation</blockquote><blockquote>“Let go of the past and go for the future. Go confidently in the direction of your dreams. Live the life you imagined”.</blockquote><p>Let’s get started… 🙂</p><h4>What is gitk?</h4><p>The <em>gitk</em> is the git repository browser. Displays changes in a repository or a selected set of commits. This includes visualizing the commit-graph, showing information related to each commit, and the files in the trees of each revision.</p><p>Historically, gitk was the first repository browser. It’s written in <strong>Tcl/Tk</strong> <em>( Tool Command Language and Tk is a graphical user interface toolkit)</em> and started off in a separate repository but was later merged into the main git repository.</p><p><strong>gitk </strong>--all: Show all branches.</p><p><strong>gitk </strong>--since=&lt;date&gt;: Show commits more recent than a specific date.</p><p><em>for e.g.</em> <strong>git </strong>--since=”2 weeks ago” : Show the changes during the last two weeks to the file <em>gitk</em>. The “--” is necessary to avoid confusion with the branch named <em>gitk.</em></p><p><strong>gitk </strong>--until=&lt;date&gt;: Show commits older than a specific date.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/1*eZSYA_zF_PDDVqPzHFJKdw.png" /></figure><p>This command will open a git repository browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HopW1pEq-qgMYH9iRcv5LQ.jpeg" /></figure><h4>Understanding Comparing files with diff</h4><p>The main objective of version control is to enable you to work with different versions of files. Git provides a <strong>diff </strong>command to let you compare different versions of your files. The most common scenario to use <strong><em>diff </em></strong><em>is</em> to see what changes you made after your last commit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*etVQlPAHg_B74hY_1VJbIw.jpeg" /></figure><p>The above image shows our remote repository.</p><p>for e.g: Let’s say, you have changed the file <em>index.txt. </em>Suppose, you want to view what you have changed in the <em>index.txt</em> file. To view the differences we need to run <strong>git diff</strong> [<em>file-name</em>] command.</p><p><strong>git diff</strong> : Compares the working directory with index, i.e. shows the changes that are not staged yet.</p><p><strong>git diff --staged</strong> [<em>file-name</em>] : To view the changes in the staging area you need to use <em>--staged</em> flag.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/805/1*flBwVe3V-F-axIR2gXfcog.jpeg" /></figure><p>The text in red color shows the previous content which was overwritten with the new content which is in green color as you see in the above image. Now, commit the changes and push to the remote repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/765/1*BvTad46UxHmUi_vzbxPicw.jpeg" /></figure><p>To view changes in the remote repository, see the image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YPX-_2tk_tmsQAJQhwe-xA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dN2s2ucXtYF5iWSkOBRiEg.jpeg" /><figcaption>This the place where you can view your commits.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j3HHoFGn6-KF6E7GqvkziQ.jpeg" /><figcaption>The pink color simply means removed contents, and green color means added new content at the place of the previous commit.</figcaption></figure><p>For e.g: Let’s say, you again changed <em>index.txt </em>and added the file in the staging area.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/743/1*2KASvsZ7tT89EwiHq1nlzA.jpeg" /></figure><p>As you see in the above image, The command <strong>git diff</strong> doesn’t show anything it because the <em>index.txt</em> file is in the staging area. Once you add the files in the staging area, the git diff command won’t show anything. So, to view the changes in the staging area. You need to run <strong>git diff </strong><em>--staged</em> <strong>[file-name]</strong> command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/648/1*IKq4QVCqg_fN5RgEptbQhA.png" /></figure><p>After some time your team member says that you have to remove that “<strong><em>- good</em></strong><em> </em><strong><em>one</em></strong>” from the ‘<strong><em>index.txt</em></strong><em>’ </em>file. Now, you have to reset the changes, but how? Let’s understand, firstly you have to unstage the files <em>index.txt </em>because it’s in the staged area right now. We use <strong>git reset </strong><strong><em>[file-name]</em></strong> to unstage.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/741/1*e6J8RhXzZNbhMoVOT59hXg.jpeg" /></figure><p>Then after, you have to run the<strong>git checkout </strong><strong><em>[file-name]</em></strong> command. This command is to updates files in the working tree to match the version in the index or the specified tree or we can say, it switches branches or restores working tree files.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/690/1*zReTjDW9M_jz9cDl7i3cTQ.jpeg" /></figure><p>Now, to view the contents of a file in git bash use <strong>git show </strong><strong><em>:[file-name]</em></strong> .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/724/1*FY5dzm4_xX3DqmSzlkUAPA.jpeg" /><figcaption>The index.txt file is reset successfully</figcaption></figure><h4>Understanding branches in git</h4><p><strong>Branching</strong> is a feature available in the most modern version control system. Branching in other version control systems can be an expensive operation in both time and disk space. In <strong>Git</strong>, branches are a part of your everyday development process. Git branches are effectively a pointer to a snapshot of your changes. When you want to add a new feature or fix a bug-no matter how big or how small -you spawn a new branch to encapsulate your changes. This makes it harder for unstable code to get merged into the main codebase, and it gives you the chance to clean up your future’s history before merging it into the main branch.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MzdzZ1KxfolwMfLSFCzRYw.png" /></figure><p>The diagram above visualizes a repository with two isolated lines of development, one for a little feature, and one for a longer-running feature. By developing them in branches, it’s not only possible to work on both of them in parallel, but it also keeps the main master branch free from questionable code. A branch represents an independent line of development. Branches serve as an abstraction for the edit/stage/commit process.</p><p>The git branch command lets you create, list, rename and delete branches. It doesn’t let you switch between branches. For this reason, the <strong>git branch</strong> is tightly integrated with the <strong>git checkout</strong> and <strong>git merge</strong> commands.</p><p><em>For e.g: Suppose, you want to add a login feature on our website so you will create the login.txt file in your working directory. But, you feel that what happens when an error occurs, if errors occur it will disturb the flow of our website because it will disturb our master branch. So, you think let’s create another branch named </em><strong><em>“login-feature”</em></strong><em> and try to implement the login feature in this branch. If the newly added login feature gives an error, then no problem? because our previous code will be working properly. How? because it’s in a different branch and our previous code is in the master branch.</em></p><pre><strong>git branch </strong><em>&lt;branch-name&gt;</em></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/739/1*GGTaYtv6w9d4w_qU8SDoKQ.jpeg" /></figure><p>In the above image, we see that the <strong>“<em>master”</em></strong> occurs in <em>green</em> color with an asterisk <strong>(*)</strong> symbol which means we can currently on the master branch then use the command <strong>ls</strong> to view the files in the master branch as you can see we also have a branch called <strong>‘<em>newsBranch’</em></strong> in that we also have a file called news.txt which was not in the master branch. So, the command <strong>git branch </strong>is used to view the branches in the repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/1*2SPV7lePCP121gqStHIp4g.jpeg" /></figure><p>As you see, we created another branch called <strong><em>login-feature</em></strong> which has all files the same as the master branch. Now, we will be created a file named <strong><em>login.txt</em></strong> in this branch.</p><p>The command <strong>git checkout</strong> <em>&lt;branch-name&gt;</em> is used to switch the branch.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/702/1*s9M0yTI3FIwhPCxVC-Zplg.jpeg" /><figcaption>We successfully created the login.txt file.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/729/1*4Q6gDvgKepOt2SNBsm-9BA.jpeg" /></figure><p>Then after, you pushed your login feature on the remote repository. Let’s have a look at our remote repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*stk4-VaRi5Y94_SXC_yenw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ve9P2VyWvUAVyk_Z_5fwOw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*annYDPZwOZR7rzw2DNGhfA.jpeg" /></figure><p>You see that our remote repository is updated with the new branch and having the login.txt file. After adding the login feature you think it’s working perfectly fine, let’s merge this branch into the master branch means our default branch. So, to merge the branch we have to use <strong>git merge</strong> <em>&lt;branch-name&gt; </em>command<em>.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/738/1*kelcyqPeMApf8hRJXwkRkw.jpeg" /></figure><p>To merge the login-feature branch into master firstly you have switched to the master branch then run the git merge command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4lbULCnN2UppsoYwtmq0TQ.jpeg" /></figure><p>Now, after successfully merging the login-feature branch and there no need for a login-feature branch now. So, let’s delete that branch.</p><h4>Deleting a local/remote</h4><p>To delete the branch from your system. The command is <strong>git branch -d</strong> <em>&lt;branch-name&gt; .</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/786/1*15mbPVLjilr8icgeHwbIow.jpeg" /></figure><p>As you see in the above image, the login-feature branch is successfully deleted from our system. But, if you see in the remote repository the login-feature is still there as you see in the below image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bGiLHi3GPDx-gL2Ol28YOg.jpeg" /></figure><p>So, to delete this branch from remote repo the command is <strong>git push origin --delete</strong> <em>&lt;branch-name&gt; .</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/782/1*nc84g3NMSWjdzFxnnbbt1Q.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3HbPuCjD2JC0BPnRoOXFew.jpeg" /></figure><p>We successfully deleted the branch from the remote repository.</p><p>Do clap 👏 the post as much as you can to show your support and motivate me to write more.</p><p>Thank you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4bd9890d68b0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mindorks/what-is-git-diff-git-branch-4bd9890d68b0">What is git diff &amp; git branch</a> was originally published in <a href="https://medium.com/mindorks">MindOrks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>