# Understand Basic of GIT

Hi Friends, if you're a little bit curious about software development, you must heard the name Git at least once, and your reading this article means your interested to know the Git, so lets start to know basic idea of git,

<mark class="bg-yellow-200 dark:bg-yellow-500/30">GIT IS VERSION CONTROL SYSTEM - this line summarize git in 1 line,</mark>

in software we don't have final product right, look at instagram, it relased so many new updates we have to update instagram in few month right,

like suppose your publish your own product and relased it new version but due to some code error - latest version product crash in some of the user system, now you have to delete this latest version code and now you want previes version code which was working fine, so you can re build latest feature and code,

now question is ? how can we go back to our previes code where we completly made changes, sometime removed old code, but now you want that old code, how can you bringe your old code back,

**here where git came**, if you ever play GIA V video games, in that game it has multiple levels right, where you progress level by level, so if your at level 5 and next month you again open that game, you will still be at same level right, where you left and if you want to play previews levels you can play why because we have check points there level 1, level 2 like that,

![](https://cdn.hashnode.com/uploads/covers/678b980cb5c65c2c71ab4ab1/5ec88c0f-b3aa-4493-b16e-083e6365ab15.gif align="center")

in git we called this commit, think git commit as game level, in first commit we add basic feature and 2nd commit little more feature and 3rd same little more more feature, so as git is tracking all this 3 feature, in future if we are facing issue due to feature which we made in 2nd commit, we can go back to 2nd commit and fix that issue,

**FUN FACT :** do you know who creator of git ? , the OG Linus Torvalds which is also create Linux kernel,

![](https://cdn.hashnode.com/uploads/covers/678b980cb5c65c2c71ab4ab1/5d7a69d0-d1bd-49ed-bd48-04a4c43ab48d.gif align="center")

* * *

# \- BASIC COMMAND OF GIT :

**STEP 1 :** First, we have to install Git on our system, you can reffere this official git website for download : [GIT LINK](https://git-scm.com/install/)

* * *

**STEP 2 :** Now if you have installed Git on your system, but this does not mean it will automatically track your files. You first have to tell Git to start. You can do this simply by:

![](https://cdn.hashnode.com/uploads/covers/678b980cb5c65c2c71ab4ab1/49fc84b7-500e-4b81-bd14-832642acfc05.png align="center")

here git is not active now how can we activate git ???

> command : git init

![](https://cdn.hashnode.com/uploads/covers/678b980cb5c65c2c71ab4ab1/be9e40f2-56e9-46ee-9917-e0ea36412503.png align="center")

can you see that **U** ,

it simply mean **untrack**, now it not like git start tracking this file, it mean git is on but it not tracking this main.txt file, now if you want to track this file, how you gona do this ? lets see in step 3 -

* * *

![](https://cdn.hashnode.com/uploads/covers/678b980cb5c65c2c71ab4ab1/17a57205-c4c9-4dd4-bbd1-bc6731927cdd.png align="center")

**STEP 3 :** Now Git is active. We just have to tell it which file we want to track, right? We can do this simply by:

> **command : git add file\_Name**

But what if you want to track all 10 files? You can simply use this command:

![](https://cdn.hashnode.com/uploads/covers/678b980cb5c65c2c71ab4ab1/9e18d1bb-a569-469d-9f05-88f0311a1ad2.png align="center")

here **A** mean **Index Added**, now git start tracking this file,

* * *

**STEP 4 :** Now you want to save this code and add a commit so in the future, whatever you want, you can come back to this code. For this, you can use the command:

> `command : git commit -m "Commit message"`

Here, you have to add a commit message so you can know what changes have been made and what features you added.

![](https://cdn.hashnode.com/uploads/covers/678b980cb5c65c2c71ab4ab1/91d116a1-2211-4441-b24f-dc3399eba000.png align="center")

* * *

**STEP 5 :** Now you want to know how many checkpoints you have created, so you can simply use this command:

> **command : git log**

Now you can know how many checkpoints you have.

![](https://cdn.hashnode.com/uploads/covers/678b980cb5c65c2c71ab4ab1/b63df58f-6319-49f9-ace7-116d146a86ac.png align="center")

### DIAGRAM OF GIT COMMIT ID : for better undestanding

here we used this diagram as example, as we only have 1st commit but in future we will have multple commit,

![](https://cdn.hashnode.com/uploads/covers/678b980cb5c65c2c71ab4ab1/17a57205-c4c9-4dd4-bbd1-bc6731927cdd.png align="center")

* * *

**STEP 6 :** Now, if you want to check what changes I made between the 1th and 2th commits, I can use this command.

![](https://cdn.hashnode.com/uploads/covers/678b980cb5c65c2c71ab4ab1/866194fc-bf1b-438d-a2b7-5779a8aca0e1.png align="center")

now we add more data and also add 2nd commit, if you want to know what exactly i made changes betweet commit 1 and commit 2, we can do using this command,

first have to know both commet id : we can do using **git log** command

![](https://cdn.hashnode.com/uploads/covers/678b980cb5c65c2c71ab4ab1/4cbd3cf5-69af-4dfb-89aa-88560053cef0.png align="center")

`command : git diff 1st_commit_ID 2nd_commit_ID`

![](https://cdn.hashnode.com/uploads/covers/678b980cb5c65c2c71ab4ab1/26c0cf7e-8687-455c-8409-d5ed3c0aaf62.png align="center")

here you can see in red,

after 1st commit we add git at line number 2nd and also at line number 6 as add one more line,

**NOTE :**

IF YOU WANT TO ADD NEW COMMIT, YOU HAVE TO FIRST USE THIS **COMMAND :**

> 1st command: git add file\_name
> 
> 2nd command : git commit -m "commit massage"

* * *

**STEP 7 :** you want to undo one of your commit code, but how ?

Currently you have 4 commit :

![](https://cdn.hashnode.com/uploads/covers/678b980cb5c65c2c71ab4ab1/f2c8a67c-df96-42ee-985e-de5fcfd95f62.png align="center")

**1st commit** - 27a6699a74182283b140393e819eb79fa8d9ba3 - added home page

**2nd commit** - c6a9b1d4da2fe036d6f8f04a4d162491acc1def9 - payment gatway section

**3rd commit** - 5e3e4d40ed9222566d419e5d86dffbe91efb1622 - added chat section

**4th commit** - 9a96b66662b1c96208f3b82092b484b27ac5aeb0 - added video section

now you don't want to use 2nd commit payment gatway code, so we can simply use command,

> **<mark class="bg-yellow-200 dark:bg-yellow-500/30">COMMAND </mark>** <mark class="bg-yellow-200 dark:bg-yellow-500/30">:</mark>  
> <mark class="bg-yellow-200 dark:bg-yellow-500/30">git revert c6a9b1d4da2fe036d6f8f04a4d162491acc1def9 [ 2nd commit id ]</mark>

now new 5th commit will be created

**5th commit** - 27a6699a74182283b140393e819eb79fa8d9ba2d

it will be same as 4th commit code but only this commit will removed 2nd commit payment gatway section code,

![](https://cdn.hashnode.com/uploads/covers/678b980cb5c65c2c71ab4ab1/d25644c2-1569-4354-900e-b20293802489.png align="center")

> NOTE : THIS COMMAND <mark class="bg-yellow-200 dark:bg-yellow-500/30">DID NOT DELETE CODE PERMANATLY,</mark> SO YOU CAN RESTORE THAT CODE AGAIN

* * *

**STEP 8 : you want to delet commit code permanatly and also delet next all commit also**

you have commit : 1st --> 2nd --> 3rd --> 4th --> 5th

and if you want to delete 4th and 5th commit parmanatly then you can use command

> **git reset** **\--hard** 5e3e4d40ed9222566d419e5d86dffbe91efb1622 **\[ 3rd\_commit\_ID \]**

so now you have 1st --> 2nd --> 3rd

NOTE : this is not mostly recomanded for biggenear, who are new to git as this command delet code permanatly,

so if you read this article, so hope you get basic idea of git, Thank you so muc for reading !

![](https://cdn.hashnode.com/uploads/covers/678b980cb5c65c2c71ab4ab1/418f2eb8-1da0-4452-acc6-d33ee5e92437.gif align="center")
