# Git Essentials for Beginners: Basic Commands Explained

**Git: What is it?**  
**1\. A Distributed Version Control System (DVCS) is what Git is.**

* Version control lets you “time travel” back to any earlier version of a file by tracking every modification made to it.
    
* Distributed: Every developer has a complete copy of the project history on their own computer, not just on a central server, in contrast to earlier systems.
    

### **Why Git is Used :** 

* **Safety:** You can quickly restore your code to a functional state if it is broken.
    

* Collaboration: Several people can work on the same file at once without erasing each other’s contributions.
    
* Experimentation: Testing new features is possible with “branches” that don’t interfere with the main project.
    

### Fundamentals of Git and Key Terminologies:

The Three Trees (or stages) of a project must be understood in order to comprehend Git:

* **Working Directory:** The actual files on your computer that you can view and modify.
    
* **Staging Area (Index):** A “preview” area is the staging area (index). You inform Git of the modifications you wish to incorporate into the upcoming snapshot.
    
* **Repository (Local):** Git keeps snapshots (commits) in a repository (local).
    

**Key Terms Repository (Repo):** 

A Git-tracked folder that includes the project files and the`.git` history folder.

* **Commit:** A snapshot or “save point” of your project at a particular moment in time.
    
* **Branch:** An alternate version of your repository, typically referred to as `master` or `main.`
    
* **HEAD:** A pointer that shows which commit or branch you are working on right now
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1767451418870/4e51b83a-f2f4-4ac0-ae33-509ebc9fcd42.png align="center")

## Common Git Commands: A Practical Workflow

Let’s walk through a basic developer workflow from scratch.

**1 - Beginning a Project**  
Open the terminal, navigate to your project folder, and type `git init.`  
As a result, a hidden`.git folder` is created. You now have a Git repository in your directory.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1767452384190/f79d740b-45b1-4d59-bcfa-bcfd88d75f2c.jpeg align="center")

**2 - Verifying the** `git status`  
Do this frequently. It indicates which files have been altered and if they are "staged" or not.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1767452487250/5920fedc-5c7f-454e-b45b-0a1700c3dc4f.jpeg align="center")

**3 - The Two, Step Save (Add & Commit)**

Git works in such a way that you have to explicitly select what you want to save.

Step 1: Stage the file `git add index.html` (or `git add .` to stage everything)

Step 2: Commit the file `git commit, m "Add initial JS File"` The -m is short for message. Please, always make these as descriptive as possible!

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1767452670310/09ffab00-459c-480b-957f-e38e2143f37c.jpeg align="center")

**3 - Viewing History**

`git log`

This shows a chronological list of all commits, who made them, and the unique SHA-1 hash (ID) for each.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1767452724354/026a6653-9156-4934-82ad-b96c6e05b76b.jpeg align="center")

### Summary Table: Essential Commands

| **Command** | **Description** |
| --- | --- |
| `git init` | Initializes a new local Git repository. |
| `git status` | Shows the state of the working directory and staging area. |
| `git add <file>` | Adds a specific file to the staging area. |
| `git commit -m "msg"` | Saves the staged snapshot to the repository history. |
| `git log --oneline` | Shows a condensed version of the commit history. |
| `git diff` | Shows the exact line-by-line changes made to files. |

## A Note for the Skeptical Developer

One thing to be careful about: in its fundamental storage, Git doesn't really keep "diffs" (the differences between files), but it keeps snapshots. Every time you commit, Git makes a snapshot of the way all your files look at that time. In a case where a file is not modified, Git just refers to the old identical file that it already has stored. This is the reason why Git is so quick compared to the older systems.
