# Git for Beginners: Basics and Essential Commands

Git is one of the most important tools a developer must learn. It helps manage code changes, avoid mistakes, and collaborate efficiently.

This blog explains **what Git is**, **why it’s used**, **core Git concepts**, and **essential commands**, with a simple workflow that beginners can easily follow.

## What is Git ?

<mark>Git is a distributed version control system</mark> that records changes in code and allows developers to manage different versions of a project.

Git helps you manage changes to your code over time. It keeps track of every little change or update you make, you can always look back at previous versions or undo mistakes if needed.

## Why does Git exists ?

When writing code, files change constantly. Without a system like VCS, it becomes difficult to :

* track changes or undo mistakes.
    
* Work on new features without breaking existing code.
    
* Collaborate with other developers
    

Git solves these problems by giving developers **control** while working on code.

## Git Basics and Core Terminologies

Before using Git commands, it’s important to understand a few core concepts.

1. <mark>Repository : </mark> A **repository (repo)** is a project folder tracked by Git. It contains Project files and the hidden `.git` folder.
    
2. <mark>Commit : </mark> A **commit** is a snapshot of the project at a specific point in time.
    
    Each commit includes: the changes made, a unique id, and the meesage describing the changes.
    
3. <mark>Branch : </mark> A **branch** is a separate line of development. the repo can have more than one branches.
    
4. <mark>Head :</mark> `HEAD` is a pointer that indicates the **current commit or branch** you are working on.
    

## Common git commands

1. `git init` : Initialize a Repository.
    
    ```bash
    git init
    ```
    

Creates a new Git repository by adding a `.git` directory to the project.

2. `git status` : Shows modified, staged, and untracked files.
    
    ```bash
    git status
    ```
    

3. `git add <file_name>` : Moves selected changes to the staging area.
    
    ```bash
    git add <file_name> // to stage the single file with <file_name>
          or
    git add .   // to stage all the changed files 
    ```
    

4. `git commit` : save changes from the staging area.
    
    ```bash
    git commit -m "commit_message"
    ```
    

5. `git log` : log the commit history
    
    ```bash
    git log  // detailed commits 
        or
    git log --oneline  // details in one line related to commits
    ```
    

## Understanding the Git Workflow

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1767551738516/ee397137-e71e-4dd3-b1f2-0866bb4f9026.png align="center")

1. `git init`
    
    This command converts a normal folder into a **Git-tracked repository.** Git creates a hidden `.git` directory. From this point, Git starts monitoring changes.
    
2. Working Directory
    
    The `working directory` is your project folder where you write code, edit files or delete or modify content.
    
    At this stage: `Git` sees the changes but nothing is saved yet.
    
3. `git add <file_name>`
    
    This moves selected changes to the **staging area .** You decide exactly what will be included in the next commit.
    
4. Staging Area
    
    The **staging area** is a temporary holding space.
    
5. `git commit -m “<commit_message>“`
    
    This command creates the commit. The commit is stored in the **local repository.** Each commit becomes part of the project history.
    

`git push origin <branch_name>`

Uploads local commits to a **remote repository** (GitHub, GitLab, etc.) Used for collaboration and backups

<mark>Until you push, your code exists only locally.</mark>

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1767550853196/4b41535b-91db-4e9a-ab63-2b0d94f2b51e.png align="center")

## Let’s Connect

If you’re also learning Git or just starting your developer journey, feel free to connect with me.

🔗 [Github](https://github.com/Mukul2244)

[🔗 X account](https://x.com/mukulsharma1594)

Happy coding guys…
