The beginner-friendly basic Git guide part 1

Today, I want to help you to understand the Git. No need to worry if you are not much good at it yet. I am going to make it as simple as I can in this tutorial guide.

We will cover creating a git repo, tracking changes, saving changes to the repo, and checking the history of the repo. We will cover more in the next article.

Every journey starts with a question and without questions, we don’t know where to go and what to do. So, let’s start with the first question.

What is Git? 🤔

The simple mean of Git is a version control system. You might have heard the definition, one or more times. But you may not get it in the first shot. I am simplifying this for you.

An easy point of view:

Take an example of camera or old cartoon animations movies. For the cartoon, Artist often draws multiple animations of a character and plays altogether, so; It looks like a movie is playing.

1*y6TdVOxkv8n3OI rF9bb8g

The animation drawing

But the reality is animations are playing one by one. A camera also does the same for recording videos. It captures multiple shots of objects and combines altogether and plays.

The necessary thing to understand from the last paragraph is to realize how things are working. We have every single moment that facilitates us. So, we can move here and there see what was there in the complete story.

Git does the same for us. It helps us to record every single moment of our software development phase. So, we can save things and move here and there in between any moment.

1*zNKCvWIlNljN7hFWPHW3AQ

Tracking changes

But there are some differences between the working of the camera and our beloved Git. In-camera, you get two or three buttons to control when to record and when to not. But Git offers more than this. It lets you control what to record when to record etc. But there are no buttons this time.

You have to give some instructions to Git. So, it can do the work for you. These instructions called commands. Commands are words for Git to understand and work accordingly.

Note: I am not covering the installations and setup of Git in this guide.

Keep a record of everything

Let’s say that you want to record and save your software application developing phase. So, you can move here and there and also keeps you safe if you had a bug or mistake. You can move back to any changes and fix them anytime without breaking or losing the latest changes.

To do this, you have to create a file that will keep everything in the record. It is like a notebook register of your software, where everything will be available for you. It is called a git repo. This repo keeps your software history safe to aid you.

Registering changes

Registering changes

To create a repo and save changes. You have to open CLI in your software app directory then run this command.

Running “git init” command

It will create an empty git repo. It’s time to move forward.

Tracking changes

Let’s say that you have developed a feature and want to record or register it. For this, you have to tell the Git to record or track it. For example: You have made changes into the file named hello.txt. This file contains text that you wrote in this file.

You have to check for changes. You can do with this command.

git status

Running “git status” command

It will show you all the files that have the latest changes in red lines. Note: It shows the changes in Red color if the changes not tracked yet. If changes are being tracked, then it shows in Green color.

Now to record these changes in the file. You have to run “git status” command.

running git status

Running “git status” command

It will start recording the changes in this file. In technical language, it is called the staging area where changes are being tracked but not saved until you explicitly say to Git to save.

First, understand the command above before moving forward. The first word is “git”. It means this command is only for Git. The second word is “add”, It means to start tracking or recording these changes. The third word is “hello.txt”. It is just a file name that you want to record or track or put it in the staging area. You can replace this by any file that you want to put in the staging area. Let’s move forward.

Saving changes

If you have completed a particular task, then you can save these changes by telling Git. It will be in the register (.git )

You have to run “git commit -m”Write hello” command to save the changes.

Running “git commit-m”Write hello” command

It saves your changes to the repo with the given message.

Huh, do you want to understand this command?

You know the mean of the first word. The second-word “commit,” it means to save the change.  The third “-m”, it means the message that you want to supply when the change is going to be saved. So, you can understand what changes are there in this commit. There is a text written. It is for you to write anything between quotes that describes the changes in short.

These changes that are saved in our repo, those changes are called commits in technical language. Hmm, move forward now.

See changes in history

Okay, we have saved the changes like video recording by a camera. But now what to do if we want to see the changes or commit back.

There are some commands for it also. You can supply these commands to see

Running “git log” command

It will show your commits with SHAs and messages with extra details. You can also give this command to CLI.

Running “git log — oneline” command

It will also show changes, but it will show just SHAs and messages rather than extra details about the commits.

Let’s understand both commands. The second word means to show commit logs. The third word means to show commit logs in a single line per commit. It doesn’t show extra details.

You have good enough knowledge to work with Git for now. I know there is something more that you must know. Like you got how to record a video, pause, and play it. But you don’t know how to trim a video in between or make changes. I am going to guide you in the next article. Please stay tuned for it.