<?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: Gabriela Cruz</title>
    <description>The latest articles on Forem by Gabriela Cruz (@gcruzdev).</description>
    <link>https://forem.com/gcruzdev</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%2F861697%2Fac182cbd-3f91-4c4d-8c9f-7ad7e143d6e9.png</url>
      <title>Forem: Gabriela Cruz</title>
      <link>https://forem.com/gcruzdev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/gcruzdev"/>
    <language>en</language>
    <item>
      <title>Git Basics: tracking files and adding commits</title>
      <dc:creator>Gabriela Cruz</dc:creator>
      <pubDate>Thu, 19 May 2022 00:52:46 +0000</pubDate>
      <link>https://forem.com/gcruzdev/git-basics-tracking-files-and-adding-commits-lbe</link>
      <guid>https://forem.com/gcruzdev/git-basics-tracking-files-and-adding-commits-lbe</guid>
      <description>&lt;p&gt;After downloading and installing &lt;a href="https://git-scm.com/"&gt;Git&lt;/a&gt; on your computer, you may be asking yourself &lt;em&gt;how to start using it effectively&lt;/em&gt;. I wrote this guide for myself a few weeks ago and thought about sharing it in some public platform in order to maybe help someone else, so here we go!&lt;/p&gt;

&lt;p&gt;Before all, we have to &lt;strong&gt;get our configs done&lt;/strong&gt;. Those configurations will be useful for when, later on, we make our commits. They will be "stamped" by Git with the email and name we'll set up now, as a form of identification. This definition can be done by the following commands.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git config --local user.name "Your name here"
git config --local user.email "your@mail.here"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The next step for setting our project up, is initializing git in its folder. Go to your project folder and, in its terminal, run the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code causes &lt;strong&gt;a git repository to be initialized in our folder&lt;/strong&gt;. All changed content in this repository will have its changes seen by Git (but not monitored, for now). In Git Bash, the terminal starts reporting the currently working branch.&lt;/p&gt;

&lt;p&gt;So, by now, you may be asking yourself what actually causes our file changes to be tracked by Git. Running the command &lt;code&gt;git status&lt;/code&gt;, we are able to see our commits and our "untracked files".&lt;/p&gt;

&lt;h2&gt;
  
  
  Tracking my repo files
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git add filename.ext
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Running the command above, our example file named FILENAME had its changes logged by git. Note that with each change this command needs to be run again!&lt;/p&gt;

&lt;p&gt;With &lt;code&gt;git add .&lt;/code&gt;, we log all files changed at once. That's really useful, since we may alter many files at once and instead running an add for each one, we can simply run &lt;code&gt;git add .&lt;/code&gt; and voilà. &lt;/p&gt;

&lt;p&gt;At that point, the command &lt;code&gt;git status&lt;/code&gt; we saw above starts to show changes to be commited. &lt;/p&gt;

&lt;h3&gt;
  
  
  Commiting files
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; git commit -m "new commit" 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Note that text between commas can be replaced with any message. There's &lt;strong&gt;some patterns envolving commit messages&lt;/strong&gt; and you can see some nice guide about it by checking out &lt;a href="https://dev.to/helderburato/patterns-for-writing-better-git-commit-messages-4ba0"&gt;here&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The command above commits all changes we made until now. The -m flag with a message is optional, but it's always a good practice to add it with a small explanation of the alterations you made.&lt;/p&gt;

&lt;h3&gt;
  
  
  Remotely
&lt;/h3&gt;

&lt;p&gt;So now we got our local commits and changes being tracked and registered by Git. How do we get this online? &lt;/p&gt;

&lt;p&gt;For this step, we first need to create a repository manually on a code versioning website. The most used and particularly my favorite is &lt;a href="https://github.com/"&gt;Github&lt;/a&gt;. Once you have your account created, you can create a repository and use its link to "connect" it to your local repository by running the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git remote add origin https://github.com/username/respository.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let's break down each of the command parameters we just saw.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git remote&lt;/code&gt; manages our tracked repositories.&lt;br&gt;
The parameter &lt;code&gt;add&lt;/code&gt; add a remote named &lt;code&gt;origin&lt;/code&gt; for the repository &lt;code&gt;url&lt;/code&gt; that goes at the end of the command.&lt;/p&gt;

&lt;p&gt;Now that our remote repository and our local repository can see each other, note that our changes made locally cannot be seen in the remote repository yet. Running the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git push -u origin main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we are "pushing" our local content to our remote Github repository. Note that main is the name of our remote repository, so this may vary depending on which branch you want to push. If you're still confused about branches, &lt;a href="https://git-scm.com/book/en/v2/Git-Branching-Branches-in-a-Nutshell"&gt;feel free to dig deep into the Git documentation&lt;/a&gt;. I plan on adding new parts to this guide soon, but the documentation will always be your most reliable source of information.&lt;/p&gt;

&lt;p&gt;All in all, Git might seem a little daunting at first, especially if you've never dealt with terminal commands and code versioning before. Gradually, you will get used to the syntax of the commands and make your commits almost automatically. &lt;/p&gt;

</description>
      <category>git</category>
      <category>beginners</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
