Git for Beginners: Basics and Essential Commands

If you’re new to programming or just started your developer journey, you might have heard people saying:
“Did you commit the code?”
“Which branch are you working on?”
“Can you share the repo link?”
At first, Git can feel confusing and intimidating. But at its core, Git solves a very simple problem:
👉 How do we safely track changes and work together on code without losing anything?
This article explains Git from scratch, using simple language, practical examples, and a beginner-friendly workflow.
What Is Git?
Git is a Distributed Version Control System (DVCS).
In simple terms:
Git helps you track changes in your code over time and collaborate with others without losing work.
Instead of copying project folders or renaming files like final_v2_final.zip, Git records what changed, when it changed, and who changed it.
Why “Distributed”?
Git is called distributed because, every developer has a full & independent copy of the entire project repository, including it’s complete history & version-tracking capabilities, on their local machine. So even if the internet is down or a server fails, your code and history are still safe.
Why Is Git Used?
Git is widely used to overcome issues like:
Track code changes over time with precision.
Revert mistakes easily by jumping back to a previous "save point."
Work on features in isolation without breaking the "main" stable code.
Collaborate with teams without overwriting each other's work.
Without Git, managing modern software projects would be chaotic and risky.
Git Basics & Core Terminologies
Let’s break down the most important Git concepts.
1. Repository (Repo)
A repository is a storage space or project folder tracked by Git. It allows developers to track changes, collaborate efficiently. If required, Git also allows to revert back to previous versions of the codebases.
It contains:
Your project files
The complete history of changes
Think of it as a normal folder — but with memory.
2. Working Directory
This is your actual project folder on your computer where you write code, edit files & make changes in the directory.
By default, all the files in the repository are untracked until you tell Git to watch them.
You need to specify which all the files to be tracked by Git.
👉 These changes are not tracked by Git until you tell Git to track them.
3. Staging Area
The staging area is a crucial intermediate layer between your working directory (where you prepare changes) & repository (before saving them permanently).
You choose:
Which files should be included
What goes into the next snapshot
4. Commit
In Git, the git commit command is used to record a snapshot of the project's currently staged changes in the local repository's history. Each commit acts as a "save point" (new record) with a unique identifier, a message, author, and timestamp, allowing you to track and revert changes as needed.
Each commit includes:
The changes made
Who made them
A message explaining why
5. Branch
In Git, a branch is like a separate workspace where you can make changes and try new ideas without affecting the main project. Think of it as a "parallel universe" for your code.
It allows you to:
Work on new features
Fix bugs safely
Experiment without breaking the main code
6. HEAD
In Git, HEAD is a special pointer (a symbolic reference) to the currently checked-out branch or commit.
Your current location in the Git history
Usually the latest commit of the active branch
Common Git Commands (With Examples)
Let’s walk through essential Git commands step by step.
1. git init
Initializes a new Git repository.
git init
This creates a hidden .git folder that allows Git to track your project.
2. git status
Shows the current state of your repository.
git status
It tells you:
Which files are modified
Which files are staged
What Git is tracking
3. git add
This command adds a specific file to the staging area. In this case index.html
git add index.html
To add all the files at once into the staging area, use the below command:
git add .
4. git commit
Creates a snapshot of staged changes.
git commit -m "Add initial project files"
A good commit message is:
Short
Clear
Descriptive
5. git log
Displays commit history.
git log
You can see:
Commit messages
Authors
Dates
Commit IDs
6. git branch
Lists branches or creates a new one.
git branch
Create a new branch:
git branch <branch-name>
7. git checkout
This command is used to switch between branches.
git checkout <branch-name>
(Modern alternative)
git switch <branch-name>
8. git merge
Combines changes from one branch into another.
git merge <branch-name>
A Basic Git Workflow (From Scratch)
Here’s how a beginner typically uses Git:
Initialize a repository
git initWrite or modify code
Check status
git statusStage changes
git add .Commit changes
git commit -m "Describe what you did"Repeat this cycle as you build features
This simple loop forms the foundation of professional Git usage.

Best Practices for Beginners
Commit often, but meaningfully: Small, frequent commits make it easier to find bugs.
Write clear messages: "Fixed login bug" is much better than "Updates."
Don’t commit broken code: Ensure your code runs before you take a snapshot.
Use branches: Never experiment directly on your "main" branch.
Final Thoughts
Git isn't about memorizing commands; it’s about confidence. Once you know you can't "break" the project permanently because you have save points to return to, you become a faster and more courageous developer.
Git didn't just replace pendrives; it replaced fear.




