<?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>Forem: Marcos Mtz</title>
    <description>The latest articles on Forem by Marcos Mtz (@atreston).</description>
    <link>https://forem.com/atreston</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%2F952640%2F6e2fb38e-8949-452e-bb56-0e40ef93604a.png</url>
      <title>Forem: Marcos Mtz</title>
      <link>https://forem.com/atreston</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/atreston"/>
    <language>en</language>
    <item>
      <title>Quick notes about Git Branches</title>
      <dc:creator>Marcos Mtz</dc:creator>
      <pubDate>Sat, 19 Nov 2022 19:05:42 +0000</pubDate>
      <link>https://forem.com/atreston/quick-notes-about-git-branches-3g82</link>
      <guid>https://forem.com/atreston/quick-notes-about-git-branches-3g82</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;From the book Beginning Git and GitHub - Tsitoara&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;A commit can contain information about its author, date, the project snapshot and &lt;em&gt;the name of the previous commit.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The name of the previous commit is called parent and every commit except the first one has at least a parent.&lt;/p&gt;

&lt;p&gt;Branches are made when two different commits have the same parent.&lt;/p&gt;

&lt;p&gt;Simply speaking, a Git branch is just a simple reference to one commit in a list of chained links.&lt;/p&gt;

&lt;p&gt;Git uses a special reference called &lt;code&gt;HEAD&lt;/code&gt; to get information about which branch we are currently working.&lt;/p&gt;

&lt;p&gt;Git branches are stored in files inside the &lt;code&gt;.git/refs/heads/&lt;/code&gt; folder and they contain the hash string of the latest commit for that branch. &lt;/p&gt;

&lt;p&gt;If you are checking out a previous version using a hash string instead of a branch name, you will fall into a state called &lt;em&gt;detached HEAD&lt;/em&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Caution&lt;/strong&gt; Just like human bodies, never be in a state of “detached HEAD” if you can avoid it. It is a very dangerous situation to find oneself in.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;For most situation, you can think of HEAD as the reference to the current branch, and every commit you create will use the last commit in that branch as a parent.&lt;br&gt;
    - No parents: The very first commit&lt;br&gt;
    - One parent: Normal commit in a branch&lt;br&gt;
    - Multiple parents: A commit created by the merge of branches&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt; Like when we navigated between versions, you can’t switch branches if you have uncommitted changed files. Commit before you move. Or use a technique called “stashing” that we will see in later chapters.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tip&lt;/strong&gt; To immediately switch to a new branch after creating it, use the option “-b” with the git checkout command. For example, “git checkout -b testing” is the same as “git branch testing” and then “git checkout testing.”&lt;br&gt;
&lt;/p&gt;


&lt;/blockquote&gt;

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

&lt;/div&gt;



&lt;p&gt;To delete a branch, simply use the same command as to create one but with the option “-d.”&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git branch &lt;span class="nt"&gt;-D&lt;/span&gt; branchname
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>git</category>
      <category>github</category>
    </item>
  </channel>
</rss>
