DEV Community

Cover image for An introduction to Git: My first commit
Juan Almanza
Juan Almanza

Posted on

An introduction to Git: My first commit

What is Git?

Git is a version control system initially created by Linus Torvalds, the same creator of the Linux kernel. Git was born when the linux kernel used a version control system called BitKeeper, but this was proprietary (or closed source) and when the kernel contributors decided to look at other systems they found that none of the alternatives at the time were sufficient.
Linux Trovalds
Git allows us to manage, distribute and collaborate on our code so that it is organized and there is an efficient workflow when programming with several people, it will also help us to do things like going back to previous versions of our project, or see what the other people who collaborate on our project have programmed.

Installing Git

You can install Git on your computer in several ways, the easiest is if you have a package manager, such as aptitude, brew or chocolatey.
if you have some of these just run this line in your terminal, if you are on linux or MacOS and it does not work correctly you can run it with the sudo instruction at the beginning of the command.

{ apt | brew | choco } install git
Enter fullscreen mode Exit fullscreen mode

if you do not have package managers installed you can see these tutorials to do it in windows:

and also for linux and MacOS:

Let's start with Git

To start let's create a folder, and open that folder in the terminal, then we must initialize our repository, for that we execute the command git init and it should say that the repository has been initialized and now we can start managing versions in our code.
To start executing commands we are going to create a code example, in this case an HTML document where we are going to create a Christmas wishlist.

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title>Wishlist</title>
  </head>
  <body>
    <h1>Wish List for christmas</h1>
    <ul>
      <li>Be a superhero</li>
      <li>Buy a Mansion with my junior salary</li>
      <li>visit the <a href="https://scidroid.me">SciDroid's Web</a></li>
    </ul>
  </body>
</html> 
Enter fullscreen mode Exit fullscreen mode

When we save this file we can make a commit, which will allow us to save the changes in this file. let's see the example.
The first thing we will do is to add the file to git, for this we will do the following command git add index.html
This command will make git start checking the changes in our file, and the last step before making our first commits is to execute these commands to identify ourselves.

git config --global user.name "John Doe"
git config --global user.email johndoe@example.com
Enter fullscreen mode Exit fullscreen mode

Just change the name and email to your name and email address.
Now the last part is to make a commit, just run the following command and change the message to the one you like.

git commit -m "message"
Enter fullscreen mode Exit fullscreen mode

and if everything went well, congratulations you have done your first commit, now keep learning because git is an essential tool in development.
Thanks for reading.

Top comments (0)