Git for Beginners: Basics and Essential Commands

Git for Beginners: Basics and Essential Commands
When i first started coding, I was often terrified of making mistakes and breaking projects, as we all heard that one line, “If the code is working, don’t touch it“. We’ve all been there, making dozens of copies of folders like my-project-v1, my-project-v2, and my-project-FINAL. It looks like a mess!
That’s where we use Git. As beginners, we can think of Git as a "Save Game" system for our code. It is like a time machine for the code.
What is Git?
Git is a Distributed Version Control System (DVCS).
Version Control: It tracks every change you make to your files. If you make a mistake, you can revert to a previous version.
Distributed: Every developer has a full copy of the project history on their local machine, not just on a central server. This makes it fast, reliable, and great for collaboration.
Git is a tool that sits on our computer and watches our project folder. It keeps track of every single change we make.

If we delete something by accident? Git can get it back for us.
If we had made some mistakes, we could reverse them. And it’s very useful in production.
If our code worked yesterday but broke today? Git can take us back to yesterday’s version in seconds.
It is the ultimate "Undo" button for our folders.
Why Git is Used?
Collaboration: Multiple people can work on the same project without overwriting each other's code.
Experimentation: we can create "branches" or can say Copy to try new features safely.
Traceability: Every change is labelled with who made it, when, and why(Message of commit).
Git Basics and Core Terminologies:

Before seeing commands, we need to understand some important concepts that we will hear again and again in your journey:
Repository (Repo): A folder that Git is tracking. It contains all project files and their entire history.
Commit: A snapshot of your files at a specific point in time. Think of it as a save point in a video game.
Branch: A parallel version of your repository. The
mainbranch is usually the production-ready code, while other branches are for features or fixes.HEAD: A pointer that indicates which branch and commit you are currently working on.
The Stage: This is the waiting room. You put your files here before you officially save (commit) them.
Essential Git Commands:

git init: Transforms our current directory into a Git repository. Start watching the folder!Doing
git initcreates a special folder as.git/in our project and it will be hidden.git status: The most important command. It tells us which files are tracked, untracked, or staged. tells what’s happeninggit add <filename>: Moves changes from the Working Directory to the Staging Area(Waiting room).git add.: To move all files in the current folder to the staging area at once.git commit -m "Your message": Saves the staged snapshot to the Repository history. Save our progress forever and label it with a message.git log: Show us a list of all the save points we have ever made.git diff: To see modifications/changes from one file to another. And this modification history is stored in .git/ folder.
A Simple Workflow:

Here how it looks like when we use Git:
Start a project: We create a folder and type
git init.Write some code: We create a file called
index.htmland write "Hello Kartikey!" in it.Check on Git: We type
git status. Git will show our file in red because it is new and hasn't been saved yet.Prepare it: We type
git add index.html. Now it's in the staging area, the "waiting room"!Save it: We type
git commit -m "Added my index file".
Here We just created our first version. If we delete that file now, Git can bring it back because we committed it!
Some Video Resources to learn it:
These Resources are enough to start, learn from anyone!
In Hindi:
In English:





