# Git for Beginners: Basics and Essential Commands

In this article, we will learn about:

1. Git Basics and Core Terminologies
    
2. Common Git Commands
    

Git is a distributed Version Control System (VCS), i.e., it helps you to track changes in your code and work with other people without messing things up.

Core concepts:

**Repository:** A repository is a project tracked by git  
If a folder has .git directory, then its a Git repository

**Commit:** A saved snapshot of your project at a specific point in time  
Commit lets you go back, build reliable history, give informational messages

**Branch:** Parallel timeline of work  
It lets people work independently on same files, avoid breaking main code

**Head**: a pointer that tells you where you currently are  
points to latest commit in your branch

## ***Essential Commands***

### `git init`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1768592684434/5e78b631-e363-4995-a6b6-16327d864fe5.png align="center")

This command is used to initialise Git Repository inside the folder, it creates the .git folder, inside directory.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1768592699483/ddfc3bc0-f76f-4f97-bf12-7ff85402f7f5.png align="center")

This shows the folders inside .git folder, here the changes are tracked and stored

### `git add` and `git commit`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1768592873066/b3916531-6bf2-4de6-8eaf-30ad32f6565a.png align="center")

`git add:` It is used to add files to the staging area, make them ready for commit

`git commit:` It is used to save the changes in the staging area, along with a message

### `git log`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1768593128008/6d0f75bf-1650-4a32-93e5-111c6b2f5202.png align="center")

This command shows all the commits made by the user. It displays the hash code of the commit, basically it shows commit history  
You can also use `git log —oneline` to make it more readable

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1768593234871/8afdbac1-c8e2-481e-9fd6-7549abff47d5.png align="center")

### `git status`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1768593306059/6074ea41-249c-4471-8161-fd835be06e8e.png align="center")

This command shows the current branch, along with untracked files, and modified files

### `git diff <hashcode1> <hashcode2>`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1768593547512/ce360cf1-3470-4d56-8270-ed1c43a03892.png align="center")

This command is used to show changes between two commits  
The commits are specified using hash codes

### `git revert`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1768593966475/5ded7aff-ffcb-4fe8-9e1d-56c61f1945d9.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1768593984239/b7f35a0c-f1f7-44fd-932a-a7dcf221dca0.png align="center")

This command gives negative of a previous specifies commit.  
It can be used to remove a bug introduced in a specific commit

### `git reset —hard`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1768594202409/9bb5c47b-a27d-4f5f-a227-cdebc44c4b77.png align="center")

This command deletes the later commits, and moves the head to the specified commit  
It is a dangerous command as it is a permanent change, and data is being lost here, and the changes cant be reversed

`git reset` allows you to add the changes in later commits to a staging area

### `git branch`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1768594419253/96ae3628-ace2-4686-bf27-30a65676ae0f.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1768594745300/8529bd4b-48e6-4240-a468-837d46e41439.png align="center")

So git branch basically reads HEAD file, which stores the ref of current Branch

***Directory and files:***

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1768594917191/81aa3ccf-972d-4b8f-abca-f6bc53e9c9d8.png align="center")

“U” represents untracked files

So these are some Git Commands, hope you learned something new today.
