# Git for Beginners: Basics and Essential Commands

Before directly jumping into the question “**What Git is**”, we should know what a **version control system** is (you might have already heard that git is a version control system), so

### **What is Version control system (VCS)?**

A version control system is like a tracker for your project. It tracks any changes made in a file or a set of files and stores each version of your project so you can recall any version you want in the future.

There are different types of version control systems. One of them is **DVCS (Distributed Version Control System)**, and Git is a popular example of this.

### **What is git ?**

Git is a Distributed Version Control System (DVCS) which stores different versions of your project like a snapshot and keep the complete history of changes. Because Git is distributed, every developer has a full copy of the project on their local machine. This means developers can work independently, and even if the server goes down, the project and its history are not lost.

### **Why git is used?**

For developers git is like a blessing. There are several benefits git gives us -

1. Git gives users full control. Developer can decide when to track changes and which files to track.
    
2. When to take snapshot (commit) also in control of developer.
    
3. Whenever needed user can revert to the desired previous version of the project.
    
4. With Git user can know what exactly has changed after and before commit(means taking snapshot) or between two selected version of the project.
    
5. Developers can easily collaborate using git and work independently in their own branches and again merge together into the main project.
    

### **Before diving into how to use git first let be familiar with some Git Core Terminologies -**

1. **Repository**: A repository (repo) is a folder or directory under the control of Git where a project and its complete history of changes are stored.
    
2. **Commit**: A commit means taking a snapshot of the current version of a project and storing it in the repository.
    
3. **Staging**: Staging means selecting which files or changes should be tracked and included before committing.
    
4. **HEAD**: HEAD is a pointer that refers to the latest commit in the current branch(means where you are currently working). It represents the current state of your project.
    
5. **Branch**: A branch is an independent line of development. You can work on your own branch without affecting the main branch of the project, and merge your changes whenever you are ready. Actually Creating a new branch essentially creates a **new reference to the current commit**, so you can start making changes without touching the main branch.
    

### **Then let’s dive into how to actually use Git in your project (in your local system):**

1. Install Git in your system.
    
2. Choose a project directory and navigate to your directory using the terminal.
    
3. Initialize a Git repository in that directory -
    
    ```bash
    git init
    ```
    
    **Output:**
    
    ```bash
    Initialized empty Git repository in /home/user/myproject/.git/
    ```
    
    This command initializes a new Git repository in the project directory.
    
4. To check status-
    
    ```bash
    git status
    ```
    
    **Output:**
    
    ```bash
    On branch master
    
    No commits yet
    
    Untracked files:
      (use "git add <file>..." to include in what will be committed)
            index.html
            style.css
            script.js
    
    nothing added to commit but untracked files present (use "git add" to track)
    ```
    
    The `git status` command tells you what has changed in your project, what changes are staged and ready to commit, and what the last commit in your repository is.
    
5. To track the files-
    
    * To track specific files use:
        
    
    ```bash
    git add index.html style.css # <-- File names 
    ```
    
    These commands move the selected files to the **staging area**.
    
    **note:** After doing this you can check with `git status` command
    
    ```bash
    git status
    ```
    
    **Output:**
    
    ```bash
    On branch master
    
    No commits yet
    
    Changes to be committed:
      (use "git rm --cached <file>..." to unstage)
            new file:   index.html
            new file:   style.css
    
    Untracked files:
      (use "git add <file>..." to include in what will be committed)
            script.js
    ```
    
    * To track all files in project directory, use:
        
    
    ```bash
    git add .
    ```
    
6. To commit your current changes -
    
    ```bash
    git commit -m "Initial commit" 
    ```
    
    **Output:**
    
    e.g. If you write something in index.html before staging, changes made after staging won’t be included in the commit unless you run `git add` again.
    
    ```bash
    [master (root-commit) abc1234] Initial commit
     1 files changed, 1 insertions(+)
     create mode 100644 index.html
     create mode 100644 style.css
    ```
    
    with this command your first version of project is stored in git repo.
    
    **note**: You must give meaningful message with each commit to understand what changes were committed by seeing this message in future ex: “Initial commit”.
    
7. To see commit history use -
    
    ```bash
    git log
    ```
    
    **Output:**
    
    ```bash
    commit abc1234 (HEAD -> master) 
    Author: Your Name <email@example.com>
    Date:   Jan 10 2026 16:55
    
        Initial commit
    ```
    
    **Note**: Here ‘abc1234’ is commit-hash and author name/email comes from your Git configuration.
    
8. To show the changes you have made in your files that are not yet committed use -
    
    ```bash
    git diff 
    ```
    
    **Output:**
    
    ```bash
    diff --git a/index.html b/index.html
    index e69de29..763b073 100644
    --- a/index.html
    +++ b/index.html
    @@ -0,0 +1 @@
    +<!DOCTYPE html>  # <-- Only this line was added in html
    \ No newline at end of file
    ```
    
    It helps you see exactly what lines were **added(+)**, **removed(-)**, or **modified** before you save a snapshot (commit) of your project.
    
    * If you want to see the changes after staging but not yet committed use -
        
    
    ```bash
    git diff --staged
    ```
    
9. To revert a desired commit (like if you have bug in any commit) use -
    
    ```bash
    git revert <commit-hash> 
    ```
    
    To find the commit-hash you have to use `git log` command and use desired commit-hash.
    
    **note**: git revert creates a new commit that undoes the changes of the selected commit(it does not delete the history). **And don’t revert the first commit**.
    
10. To see which Branch you are currently working on, use:
    
    ```bash
    git branch
    ```
    
11. To move the current branch pointer(HEAD) to a specific commit use -
    
    ```bash
    git reset --hard <commit-hash>
    ```
    
    **Warning:** Any uncommitted changes will be **lost**.
    
    Use only when you want to completely discard commits and changes after that specific commit. Otherwise use `git revert`
    

### **Git Workflow Overviews**

When you modify files, they are in your **Working Directory**. The `git add` command moves these changes into the **Staging Area** (or Index), which is like a temporary holding spot. Finally, `git commit` takes a snapshot of everything in the staging area and permanently saves it to your local **Repository**.

### **Conclusion**

Git is a powerful tool that helps developers track changes, manage different versions of a project, and collaborate with others efficiently. In this blog, we learned what Git is, why it is used, some core Git terminologies, and how to use essential Git commands through a basic workflow.

Thanks for reading & Happy coding

### References

* Git Official Documentation: [https://git-scm.com/docs](https://git-scm.com/docs)
    
* Chai aur Code – git & github series
