<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Mr CaT</title>
    <description>The latest articles on DEV Community by Mr CaT (@mrcat323).</description>
    <link>https://dev.to/mrcat323</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F461090%2F7fc02d87-4e8f-4e46-b766-6b7091def12a.jpeg</url>
      <title>DEV Community: Mr CaT</title>
      <link>https://dev.to/mrcat323</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mrcat323"/>
    <language>en</language>
    <item>
      <title>Purpose of branches in Git</title>
      <dc:creator>Mr CaT</dc:creator>
      <pubDate>Mon, 31 Aug 2020 17:32:55 +0000</pubDate>
      <link>https://dev.to/mrcat323/purpose-of-branches-in-git-807</link>
      <guid>https://dev.to/mrcat323/purpose-of-branches-in-git-807</guid>
      <description>&lt;p&gt;Hello everyone! How are you all doing ? Now it's time to tell you about branches in Git, it's a bit obvious, almost every of you know what is a branch and how to use them, but there is a nuance, not every of you use it correctly as it supposed to be used and probably do not know &lt;em&gt;how to create, delete, restore&lt;/em&gt; it. So in this post, I'll show you how to do it. &lt;/p&gt;

&lt;h2&gt;
  
  
  What is actually a branch ?
&lt;/h2&gt;

&lt;p&gt;So the branch is a lightweight movable pointer to one of commits in your repository, by default you're given a &lt;strong&gt;master&lt;/strong&gt; branch which also points to the last commit you'd made. Everytime you make commits, the pointer of &lt;strong&gt;current branch&lt;/strong&gt; moves forward automatically and it's not a special branch, you can also create them. It's mostly used for making backups of certain version of the sotware &lt;em&gt;(just in case creating a copy of a branch)&lt;/em&gt; or split up the development process, dividing the feature from each other, not worrying about other things to happen in the project, but only to focus on a thing you're working on. When you create a branch upon your &lt;strong&gt;master&lt;/strong&gt; branch, your last commit on your new branch will be the last commit of your &lt;strong&gt;master's&lt;/strong&gt;, which means that you just copy the branch that you were on. To create a branch, you just do:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;git branch &amp;lt;branch-name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;and to checkout them, you need to do:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;git checkout &amp;lt;that-branch-you-created&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;but there is a better way of creating them and checkouting them at the same time, and almost every of you guys know that, just say:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;git checkout &lt;span class="nt"&gt;-b&lt;/span&gt; &amp;lt;branch-name
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The option &lt;code&gt;-b&lt;/code&gt; says to &lt;code&gt;checkout&lt;/code&gt; &lt;em&gt;"Hey man, I'd like you to first of all create a new branch with this name, and then checkout it"&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;To view all branches, you can do:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;git branch &lt;span class="nt"&gt;-a&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;which will view all branches, either remote or local ones. Understanding the difference of remote and local branches is obvious, you are going to face something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lIUrkcla--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/dw4dd7h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lIUrkcla--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/dw4dd7h.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see the current branch is highlighted with &lt;em&gt;green color&lt;/em&gt; and remote ones are highlighted with &lt;em&gt;red&lt;/em&gt; one. Also near the current branch you probably can see star sign (*) on the left side. For viewing only remote branches, you need to say something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;git branch &lt;span class="nt"&gt;-r&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Here is the result:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qrWR78kF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/DkqLpk9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qrWR78kF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/DkqLpk9.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see that we have a few remote branches which starts with &lt;em&gt;prefix&lt;/em&gt; of &lt;strong&gt;origin&lt;/strong&gt; and as you can see &lt;strong&gt;origin/master&lt;/strong&gt;, the remote version of our &lt;em&gt;master&lt;/em&gt; branch.&lt;/p&gt;

&lt;p&gt;But it's a boring, don't you think ? Let's move on.&lt;/p&gt;

&lt;h2&gt;
  
  
  Deleting the branches
&lt;/h2&gt;

&lt;p&gt;Deleting is obvious process in git, let's say, you created a branch, worked on it, merged it, and want to remove it properly like &lt;em&gt;"I don't need you"&lt;/em&gt;, and to do that, just say:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;git branch &lt;span class="nt"&gt;-d&lt;/span&gt; &amp;lt;branch-name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;-d&lt;/code&gt; option is the shortcut of &lt;code&gt;--delete&lt;/code&gt; and it has a bit sense of humor, the git will tell you to use &lt;code&gt;-D&lt;/code&gt; option, had ever thought about of existence of &lt;code&gt;-d&lt;/code&gt; option then ? Like &lt;em&gt;Why the &lt;code&gt;-d&lt;/code&gt; option exists when it tells you to use &lt;code&gt;-D&lt;/code&gt; one ?&lt;/em&gt; and that's because git makes sure that these branches are the same (the commits) (are they merged) and if they are, &lt;code&gt;-d&lt;/code&gt; option will delete the branch, but if not, &lt;code&gt;-D&lt;/code&gt; option will delete it. It's like git warns you to make sure that you're not removing the wrong branch, it's like git hints you &lt;em&gt;Man, are you sure ? Please rethink what you want to delete&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--R5WJTv6a--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/BYVN8cr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--R5WJTv6a--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/BYVN8cr.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And of course there are times when indeed you don't need the certain branch in your local machine, so to properly delete that, use &lt;code&gt;-D&lt;/code&gt; option, which is shortcut of &lt;code&gt;--delete --force&lt;/code&gt;, like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;git branch &lt;span class="nt"&gt;-D&lt;/span&gt; &amp;lt;branch-name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--AzQUHRcq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/L6lS1eh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--AzQUHRcq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/L6lS1eh.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Git tells us that the &lt;strong&gt;feature&lt;/strong&gt; branch is deleted which its last commit hash was &lt;strong&gt;a658359&lt;/strong&gt; that also can be restored, the stuff I'll tell you a bit later.&lt;/p&gt;

&lt;p&gt;In examples above we'd viewed the remote branches and somehow, some time maybe we want to delete the remote branch on our local machine, the default deleting branches with &lt;code&gt;-d&lt;/code&gt; won't work:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--abean-Ow--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/slehqVh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--abean-Ow--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/slehqVh.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Git is looking for &lt;strong&gt;origin/feature&lt;/strong&gt; branch in our local machine that indeed doesn't exist, the &lt;strong&gt;origin/feature&lt;/strong&gt; branch is a remote branch, to delete the remote branch in our local machine we need to say:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;git branch &lt;span class="nt"&gt;-r&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt; origin/feature
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;And surely git reports us the last commit's hash of the remote &lt;strong&gt;origin/feature&lt;/strong&gt; branch&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3uJVfpTH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/zvHn0O7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3uJVfpTH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/zvHn0O7.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Deleting branches in remote repository
&lt;/h3&gt;

&lt;p&gt;Had you ever been thinking: &lt;em&gt;So I deleted a branch, in my local machine, but how can I delete it in my remote repository, how to do that ? because I don't know how to push infomation on deleting certain branch there&lt;/em&gt;. And so the answer is, you can do that in a certain ways:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;git push &lt;span class="nt"&gt;-d&lt;/span&gt; &amp;lt;remote-name&amp;gt; &amp;lt;branch-name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Either the above, or below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;git push &amp;lt;remote-name&amp;gt; &lt;span class="nt"&gt;--delete&lt;/span&gt; &amp;lt;branch-name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;And one more which might be easier to remember:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;git push &amp;lt;remote-name&amp;gt; :&amp;lt;branch-name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YN6Eqtvd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/h1bW8Ep.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YN6Eqtvd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/h1bW8Ep.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Restoring branches
&lt;/h2&gt;

&lt;p&gt;Sometimes odd things are going to happen. For example you accidently deleted the branch  you've been maintaining for a certain amount of time, you go:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;git log
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;but nothing is there. Fortunately I got good news to tell, there is an option, you can actually restore the branches you'd deleted. The question you'll ask:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;How can I do that ? There is nothing in &lt;code&gt;git log&lt;/code&gt;, My memory isn't good enough as Sherlock's or Ron White's to be able to remember the commits' hashes. So how can do that ?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;We can use an amazing command, &lt;code&gt;git reflog&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;git reflog &lt;span class="o"&gt;[&lt;/span&gt;show] &lt;span class="c"&gt;# you can add "show" or not, it'd work anyway&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;And after &lt;code&gt;show&lt;/code&gt; you can specify branch's name, it accepts all kind of arguments which &lt;code&gt;git log&lt;/code&gt; does.&lt;/p&gt;

&lt;p&gt;What it does here, it simply shows the repository records, what did happen, on what branch, from where to where someone checkouted and so on.&lt;/p&gt;

&lt;p&gt;For example we want to see the records owned by &lt;code&gt;master&lt;/code&gt; branch, just say:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--e2kN5YYI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/Z0uqLJg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--e2kN5YYI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/Z0uqLJg.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;it says that nothing else beside of cloning from github was done. Let's move on.&lt;/p&gt;

&lt;p&gt;Our purpose is to restore some branch, let's create a new one.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;git checkout &lt;span class="nt"&gt;-b&lt;/span&gt; feature
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;And add some "feature" there, it doesn't matter what we'd add, the main thing is to restore it successfully, we just open the terminal and say:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Hello World!"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; feature
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;What it does, is we just simply create a file with "Hello World!" in it. Commit it. And just do:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4r73OcSY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/LSHStLf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4r73OcSY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/LSHStLf.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We commited the &lt;em&gt;feature&lt;/em&gt; file with &lt;strong&gt;feature stuff&lt;/strong&gt; commit message.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;-v&lt;/code&gt; flag shows branches with their names and the &lt;code&gt;HEAD&lt;/code&gt;'s hash. Last commit of it. Checkout to &lt;code&gt;master&lt;/code&gt; branch and delete the &lt;code&gt;feature&lt;/code&gt; branch.&lt;/p&gt;

&lt;p&gt;Let's make sure it doesn't exist:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--eafxBfvO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/PUELY7F.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--eafxBfvO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/PUELY7F.png" alt=""&gt;&lt;/a&gt;&lt;br&gt;
The only branch we do have, is &lt;code&gt;master&lt;/code&gt;. So what now ? For instance you accidently delete a branch, or remembered that there is certain piece of code that is needed. &lt;code&gt;git log&lt;/code&gt; won't help, because it shows only commits of current branch and when you specify as a first argument the &lt;em&gt;deleted branch's name&lt;/em&gt; it will simply tell you that it doesn't exist. To restore the branch we need, tell the terminal the following:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--XZaPOLqe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/BqZ8p2t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XZaPOLqe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/BqZ8p2t.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here we see all stuff which happened in this repository, in our local machine. So we see some stuff associated with desired branch's name, &lt;em&gt;feature&lt;/em&gt;, the thing is &lt;strong&gt;to find the commit hash where it was last time used&lt;/strong&gt;. And here it is, I'll show you how:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bE1r5idt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/5HiOANr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bE1r5idt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/5HiOANr.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That is the last commit that was made on &lt;em&gt;feature&lt;/em&gt; branch, to understand how I got that, just see the text above, it says:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;HEAD@{3}: checkout: moving from feature to master&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Which means that job with feature branch is done. &lt;/p&gt;

&lt;p&gt;So what's next ? We do know the commit's hash, what to do next ? We can restore it with &lt;code&gt;git branch&lt;/code&gt; command, or &lt;code&gt;git checkout&lt;/code&gt; it doesn't matter.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4BDHzBN3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/0WtyDKx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4BDHzBN3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/0WtyDKx.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So here we're restoring the branch by its commit hash. As the second param goes hash of the commit. So we did restore the branch we desired.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git branch&lt;/code&gt; and &lt;code&gt;git checkout&lt;/code&gt; are powerful commands, their purpose is not only &lt;em&gt;creating&lt;/em&gt;, &lt;em&gt;deleting&lt;/em&gt;, &lt;em&gt;restoring&lt;/em&gt; branches, but it can also let's say retrieve the file to certain version of it. What do I mean ? I mean that we can specify a certain file, for instance &lt;em&gt;index.html&lt;/em&gt; or &lt;em&gt;work.html&lt;/em&gt; to be resetted to a certain commit, where and how it was then.  Do not reset all files, but only one (or a couple) to older version.&lt;/p&gt;

&lt;p&gt;For example, that's re-checkout to our master branch:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4j5WnXTe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/Qb1d65r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4j5WnXTe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/Qb1d65r.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;-&lt;/code&gt; sign after &lt;code&gt;checkout&lt;/code&gt; checkouts to a branch we switched from, which is &lt;code&gt;master&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xvbz3tdA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/8emsclE.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xvbz3tdA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/8emsclE.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is the list of master's commits. For example I want to change the file to version that has no &lt;em&gt;"blog"&lt;/em&gt; element in the menu, to do I just grab the commit's hash of this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1E1A3lg7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/ly85TC4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1E1A3lg7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/ly85TC4.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Because, after this commit as you can see the &lt;em&gt;Blog&lt;/em&gt; element is added, so we do:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;git checkout eb72515 index.html
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BWrkI2KY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/6aKJkoe.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BWrkI2KY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/6aKJkoe.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see checkout command didn't effect our repository, but only changed the &lt;em&gt;index.html&lt;/em&gt;, made older.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--heuPkK32--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/vqFg9qX.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--heuPkK32--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/vqFg9qX.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Also after &lt;em&gt;checkouting&lt;/em&gt; the &lt;em&gt;index.html&lt;/em&gt; file, the file automatically is added to &lt;strong&gt;index&lt;/strong&gt;, we can commit changes by:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;git commit
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;To remove the file from index to &lt;em&gt;Working directory&lt;/em&gt;, just remember the &lt;em&gt;reset&lt;/em&gt; command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;git reset index.html
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Best practices
&lt;/h2&gt;

&lt;p&gt;Better using of branches is obvious and can make your, co-workers' lives easier to understand what is what and where it is. &lt;/p&gt;

&lt;p&gt;When you're working on the certain feature, make a branch with the name of the feature, and commit every single thing you did, don't make fat, large commits, just try to make them simple to read and understand. If you want to explain what did you do in a commit, remember, commit consists of two things:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Title&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Description&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The &lt;strong&gt;title&lt;/strong&gt; is the first "field" of commit and second is &lt;strong&gt;description&lt;/strong&gt; "field"&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--eHjxCRSU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/C69YstN.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--eHjxCRSU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/C69YstN.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;title&lt;/strong&gt; must be short, and &lt;strong&gt;description&lt;/strong&gt; can be as long as you want.&lt;/p&gt;

&lt;p&gt;So here it's for this post, I'm glad that you read this, hope you learnt something from my post, stay tuned, &lt;strong&gt;farewell&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;This post firstly was posted in my &lt;a href="https://mrcat323.github.io/blog/purpose-of-branches-in-git/"&gt;blog&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>git</category>
      <category>branches</category>
      <category>bestpractices</category>
    </item>
  </channel>
</rss>
