# Git for Beginners: Basics and Essential Commands

As we have understood in the earlier blog about the need of using a version control system and what problems it solves. In this blog we will be seeing about the Basic and some essential commands of the most popular version control system - which is Git .

NOTE : If you want to first understand the reason behind the need of a Version Control System , you can go though my blog - “Why Version Control Exists: The Pen-drive Problem”. Here is the Link of my previous blog: [https://gaurangpods.hashnode.dev/why-version-control-system-exists-the-pen-drive-problem](https://gaurangpods.hashnode.dev/why-version-control-system-exists-the-pen-drive-problem)

Once you have an understanding about the need of a VCS , You can easily relate to the basic and essential commands section here.

1. What is Git : Git is the most popular Version Control System amongst all the VCS. It came into existence in 2005.
    
2. Why Git is Used : To solve the “Live Collaboration” and “Out of Sync Code” Problem.  
    Live collaboration : Multiple developers can work on the same project without overwriting each other’s work.  
    Out-of-sync Code Problem : Git keeps everything in sync using commits + branches, so nobody has to keep sending files over email / pen-drive.
    
3. Git Basics and Core Terminologies :
    
    i.) Working Directory : This is your **normal project folder** where you edit code.  
    You write code, You edit README, You add a new file etc… All of this is happening in the working directory.
    
    ii.) In day to day language what we call as “Folder”, when that folder starts containing a “.git/” folder inside it then it is called by the name of “Repository” in the world of git.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1768503922685/79991508-e43d-4186-9445-35a0362fbafc.png align="center")
    
      
    On running “git init” command we basically initialises a repository aka repo, Just remember the above Image ,it will make you understand the flow and commands easily.  
      
    iii.) Staging Area : “git add . “ moves changes from Working Directory → Staging Area.
    
    In Simple terms to take snapshot of the present code written in your IDE, use “git add &lt;filename&gt;”  
    or ” git add .” . It takes the snapshot of the code. NOTE : But It does not saves the Snapshot.  
    
    iv.) Commit : To save the snapshot , we use “Git commit -m”” ” command. The snapshot is saved in local repo  
    
    v.) Push : Then we use : “git push” which basically pushes the repository from local to the remote. So, it saves the snapshot in the remote repo ie on Server.  
    
    vi.) Branch : Think of a branch as a separate timeline of code. developers create branches like:
    
    `feature/navbar`
    
    `bugfix/login-issue`
    
    `refactor/api`
    
    They work safely there, then later merge it into `main` Branch.  
    So basically, There is one main branch of your git repo, and then to work with live collaboration , we use the concept of branch, developers create separate branches, work upon them and then merge it to the main branch if their code is not buggy,  
    
    vii.) HEAD is a file inside the “.git/” folder that contains the reference of the current branch.
    

4\. Git essential commands :

i.) To create a “.git/” folder inside any folder, In the terminal write the command “git init” inside the folder you want to create “.git/” folder .

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1768498373940/a9257116-6e00-4f5e-8a15-f7a3542b3a36.png align="center")

After running “git init” command in the terminal, wherein I have opened a folder names as “Piyush\_AI\_Series” :- You can see in the below picture that a “.git/” folder got created . However since it always is a hidden folder, hence we had to run “ls -a” command which shows/ lists all the files in that folder.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1768498526536/674d91f2-0225-4474-989b-bdee72e4e632.png align="center")

ii.) git add &lt;filename&gt; or “git add .” basically stages our code ie takes the snapshot but does not saves it.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1768501113321/75b8d17a-495e-49cf-bd2b-82ee4951c735.png align="center")

iii.) git status helps us in understanding the status or difference(if any in code) between the Working Directory and the staging Area.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1768501157257/60034795-0612-498d-b2b6-2381c2064ec6.png align="center")

iv.) git commit or “git commit -m ““ “ command basically saves the snapshot of the the code into our “.git/” folder which basically is also called as Local Repository.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1768501270503/50843275-c0bb-4530-bec8-f0dba6b173c1.png align="center")

v.) git push command basically pushes the saved snapshot from the local repository to the remote repository. Remote repository is the repository that is hosted on the servers , which in our case is Github.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1768501676842/3e1b36b0-7f6b-415b-9e25-8d74f8a070a8.png align="center")

vi.) git log is the command that gives us the information about all the commits that have been done by us.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1768501860816/912434c7-9955-4dbb-a65c-fed9f9b04452.png align="center")
