# Git for Beginners: Basics and Essential Commands

### Introduction

When you start learning programming or web development, you often hear the word **Git**. At first, it may feel confusing, but Git is one of the most important tools every developer must know.

In this blog, I will explain what Git is, why it is used, basic Git concepts, and common Git commands in very simple words. This article is especially for beginners who are just starting their development journey.

### Git is a version control system

In simple words, Git helps you track changes in your code. It stores a history of your project so you can see what you changed, when you changed it, and also you go back to an older version if something breaks in your code.

Without internet also you can use Git, because Git works locally on your computer system.

### Git is used because it makes developers life easy by solving many real-world problems

* It saves the history of your code
    
* You can undo mistakes easily
    
* Multiple developers can work on the same project
    
* It is used in almost every software company
    

In simple terms, Git makes development safely, organized and professional

### Before using Git commands, let’s understand some basic terms

A repository is like a folder that contains your project and Git history

1. Your project files live here
    
2. Git tracks all changes inside this repo which is present in Github
    

Working Directory (dir) is where you write and edit your code.  
It is the normal project folder on your computer

The staging area is where you tell Git (staging area is very initial step of git)

* These files are ready to be saved
    

A commit is a snapshot of your project at a specific time

* Each commit contains a message so that developer can understand the purpose just by reading the message
    
* It helps you understand what was changed
    

```plaintext
git commit -m "Login page updated"
```

A branch lets you work on a feature without affecting the main code

* main branch → stable cod
    
* other branches → new features or experiments
    

HEAD points to the current commit you are working on

* It tells you where you are right now in Git history
    

### Git workflow

Working Directory → Staging Area → Repository

1. Write or edit code (Working Directory)
    
2. Add changes to staging area
    
3. Commit changes to repository
    

This flow is remains going untill working on project

### Common Git Commands

To create a new Git repository

```plaintext
git init
```

Use this command inside your project folder (cmd or vs code)

To see the current state of your project

```plaintext
git status
```

It tells you :-

* Which files are changed (modified/untracked)
    
* Which files are staged
    
* What needs to be committed
    

To Add files to the staging area

Add specific file to staging area

```plaintext
git add index.html
```

Add more than one files

```plaintext
git add .
```

Saves your staged changes permanently (always write clear and meaningful messages)

```plaintext
git commit -m "Initial project setup"
```

Show commit history

```plaintext
git log
```

You can see :-

* Commit ID
    
* Author
    
* Date
    
* Commit message
    

Shows all branches

```plaintext
git branch
```

Switches between branches

```plaintext
git checkout branch-name
```

### Basic developer workflow using Git from scratch

1. Create a project folder
    
2. To Initialize Git
    
    ```plaintext
    git init
    ```
    
3. Create files and write code
    
4. To check status
    
    ```plaintext
    git status
    ```
    
5. Add files
    
    ```plaintext
    git add .
    ```
    
6. Commit changes
    
    ```plaintext
    git commit -m "First commit"
    ```
    
    This process will remains continue
    

![Explained Git Staging Area](https://imgs.search.brave.com/mj-0eEQ0yiBx6dtT57-TeTW-_2dnzcJD14iEGABpBC4/rs:fit:860:0:0:0/g:ce/aHR0cHM6Ly90ZWNh/ZG1pbi5uZXQvd3At/Y29udGVudC91cGxv/YWRzLzIwMjMvMDUv/ZXhwbGFpbmVkLWdp/dC1zdGFnaW5nLWFy/ZWEucG5n align="left")

## Conclusion

Git is a must-have skill for every developer. Even if it feel difficult at first but once you understand the basics, it becomes very easy and powerful.

Start small, practice daily, and use Git in every project you build. Over time, Git will feel natural and you’ll work like a professional developer.

Happy Coding 🚀
