# Git for Beginners: Basics & Essential Commands

If you have followed along with our previous [posts](https://writesbyankit.hashnode.dev/git-under-the-hood), you now know why version control is a lifesaver and how Git manages files under the hood. Now, it’s time to get our hands dirty. In this blog, we will move from theory to practice by covering the fundamental commands and concepts you will use every single day as a developer.

---

## What is Git?

At its heart, Git is a Version Control System (VCS). While there are many systems out there, Git is the most popular because it is “distributed” meaning every developer has a copy of the proejct history on their own local machine, not just a central server.

## Why we use Git

we use Git primarily to solve two major headaches:

1. Tracking Chnages: It keeps a chronological history of every edit, so you never lose work.
    
2. Collaboration: It allows multiple developer to work on the same code without overwriting each other’s progress.
    

## Core Terminologies You Must Know

Before we hit the terminal, let’s define a few terms that act as the pillars of Git:

* Repository (Repo): This is the folder where GIt tracks your project. It includes all your code and the hidden `.git` folder containing the history.
    
* Commit: Think this as a “save point” (Yes like in your fav. game) or a snapshot of your project at a specific moment.
    
* Branch: A parallel version of your repository. It allows you to work on new features without affecting the “Main” or stable code.
    
* Head: A pointer that tells Git which branch or commit you are currenlty looking at.
    
* Staging Area: A middle place where changes are prepared before commit.
    

## Git Workflow (The essentials)

Most of our time in Git will involve a simple cycle: making changes, staging them, and commiting them. Here are the commands to make that happen.

```plaintext
Working Directory -> Staging Area -> Repository
```

1. Starting a Project
    
    To start tracking a new or existing project, use: `git init` This command creates the `.git` repository folder in your current directory.
    
2. Checking the Status
    
    If you ever feel lost, run: `git status` This tells you which files have been modified and which ones are “untracked” (meaning Git hasn’t been told to watch them yet).
    
3. Preparing to Save (Staging)
    
    Git doesn’t automatically save every change. You have to choose which files are ready for a snapshot by moving them to the Staging Area.
    
    * `git add <filename>` : Stages a specific file.
        
    * `git add .` : Stages every modified file in your directory.
        
4. Saving the Snapshot (Committting)
    
    Once your files are in the staging area, you “lock them in” with a commit: `git commit -m “Your message”` The `-m` flag you to add a message so you (and your team) know why this change was made.
    
    Once you are in a flow, you might want to skip the staging area and commit directly. The `git commit -am "message"` command lets you do exactly that.
    
    **Wait! There’s a catch:** This is only a shortcut for *modified* files that are already under Git's watch. If you’ve just added a new `index.html` or a fresh image, this command won't see them. For new files, the old-school `git add` is still mandatory.
    
5. Reveiwing History
    
    To see the list of all presvious commits, their authors, and their unique Hash IDs, use:
    
    git log For a cleaner, one-line view of your history, try: `git log --oneline`
    

### Pro Tip: Seeing the Differences

How many times have you looked at a file you edited an hour ago and thought *"What did I actually do here?"*

This is where `git diff` becomes your best friend. While `git status` tells you **which** files changed `git diff` shows you the **exact lines** that were added or removed. It is like having a highlighter for your code’s history.

If you want to get even more specific and compare two different points in your history, you can use: `git diff commitId-1 commitId-2`

This tells you exactly how your project evolved between those two specific snapshots.

## #Beginner Tips

* Commit often
    
* Write clear messages
    
* Check `git status` before commit
    
* Don’t fear mistakes — Git can undo
    

## #Final Thoughts

Git is not just a tool, it is a safety net for developers.

Once you understand:

* working directory
    
* staging area
    
* commits
    

Git becomes simple and logical.
