Git for Beginners: Basics and Essential Commands

What is Git ?
Git is a distributed version control system that helps developers track changes in their code over time. It allows you to save different versions of your project, collaborate with others, and safely experiment without breaking the main codebase.
So, What is Git is simple words
Okay, imagine you’re working on a project and you keep saving files likeproject_final.zip, project_final_final.zip, project_final_real_final.zip
We’ve all been there.
That’s where Git comes in.
Git is basically a smart system that keeps track of all your code changes so you don’t have to worry about messing things up.
Git is like your code memory: With the help of the git you can keep the record and history of the your code Record like :
What you add in the code.
What you remove from the code.
What changes did you make in the code.
Git is like made a mistake?
No worries — Git’s got your back
This is the main website of the GIT
This is link of the Git website https://git-scm.com/
Why Git is Used
The main purpose of the git is to keep the records and history of the code. Git keeps a complete history of your project. we use Git to save our work safely and track changes in our code.
Think of Git like a save button with memory
It remembers every change you make, so you can:
Go back if something breaks.
See what you changed earlier in code.
Work without fear of losing code.
Why We Use Git (In Simple Words)
In Git, we create checkpoints at different stages of our code.
Whenever our code is working properly, we save that moment as a checkpoint (called a commit).
If later something goes wrong or an error appears, we can easily go back to the previous checkpoint and continue working from there. This helps us avoid losing progress and keeps our code safe.
Git allows us to move back and forth between different versions of our project.
You can think of it like a time machine for your code
Git helps manage the history of your code and allows you to merge changes from different branches smoothly.
So instead of creating many copies of files, Git keeps everything organized in one place.
Working of the Git
Git is a version control system, which means it keeps track of every change you make to your project. Think of it like a diary for your code that also lets you travel back in time whenever you need.

Git Basics and Core Terminologies
Git is a tool that helps developers manage their code easily.
It is mainly used to track changes and save the history of a project.
When you write code, mistakes can happen.
Sometimes new changes break old working features.
Git helps you go back to a safe point without losing your work.
Before Git, developers used to save files like:
Project_Final_v1
Project_Final_v2
Project_Final_real_v3
Project_Final_last_v4
This was confusing and messy.
Git solves this problem by keeping everything organized and clean.
Core Terminologies
| Commands | Explanation |
| Repository (Repo) | A folder where your project and its complete change history are stored. |
| Commit | A saved snapshot of your code at a specific point in time. |
| Branch | A separate version of your project used to work on new features. |
| Main / Master | The main and stable branch of the project. |
| Merge | Combining changes from one branch into another. |
| Clone | Making a copy of a remote repository on your local system. |
| Push | Sending your local code changes to a remote repository. |
| Pull | Fetching the latest code from a remote repository to your system. |
| Staging Area | A place where changes are kept before committing them. |
| Add | Command used to move files to the staging area. |
| HEAD | Points to the current branch or latest commit you are working on. |
| Remote | An online version of your repository (like GitHub). |
| Conflict | When Git cannot automatically merge changes. |
| Fork | A personal copy of someone else’s repository. |
| Checkout | Switching between branches or commits. |
| Status | Shows the current state of your working directory. |
| Log | Shows the history of commits. |
| Init | Creates a new Git repository. |
| Fetch | Downloads changes from remote without merging. |
| Rebase | Reapplies commits on top of another base commit. |
These are the some main core concepts :
A repository (repo) is a place where your project lives and Git tracks all its changes.
It stores:
Your project files
Every version of those files
Commit history
Branches and changes
Simple example:
Think of a repository like a folder with memory
It not only holds your files but also remembers what changed, when, and by whom.
A commit is like saving your work with a message so you can remember what you changed.
Think of it as a checkpoint in your project — you can come back to it anytime.
What does a commit do?
When you commit:
Git takes a snapshot of your staged files
Saves them permanently in the repository
Gives that snapshot a unique ID (hash)
Here is the example of the git commit:
git commit -m "your message"
A branch is a separate line of development where you can work on new features or fixes without affecting the main code.
Think of it like creating a copy of your project to experiment safely.
Branches help you:
Work on new features safely
Fix bugs without breaking the main project
Collaborate with teammates easily
Simple Example
You have a main project running fine. Now you want to add a new feature.
Instead of changing the main code, you create a branch:
git branch new-feature
Now you can work freely on new-feature.
- In Git, HEAD is a special pointer that represents your current working position in the repository. It usually points to the latest commit on the branch you are currently on.
If you’re diving into Git, you’ve probably come across the term HEAD. Sounds mysterious, right? Don’t worry—it’s simpler than it looks.
Think of HEAD as a bookmark or pointer in your project. It tells Git, “This is where I am right now!”
HEAD Points to Your Current Spot
Whenever you’re working on a branch (say
main), HEAD points to the latest commit on that branch.Attached vs Detached HEAD
Attached HEAD (Normal Mode):
HEAD is “attached” to a branch. Any new commits go on this branch.HEAD -> main main -> latest commitDetached HEAD (Advanced Mode):
if you checkout a specific commit instead of a branch, HEAD points directly to that commit.
HEAD -> commit 123abc
Handy HEAD Commands
git status # See where HEAD is
git log -1 HEAD # See the commit HEAD points to
git checkout main # Move HEAD to main branch
git reset --hard HEAD~1 # Go back one commit (HEAD moves too)
There are many commands in Git but the common commands are as following:
| Command | Description |
git init | Initializes a new Git repository in a folder. |
git clone <url> | Copies a remote repository to your local system. |
git status | Shows the current state of files (modified, staged, untracked). |
git add . | Adds all changed files to the staging area. |
git add <file> | Adds a specific file to the staging area. |
git commit -m "message" | Saves changes with a message. |
git push | Uploads local commits to the remote repository. |
git pull | Downloads and merges updates from the remote repository. |
git branch | Shows all branches in the project. |
git branch <name> | Creates a new branch. |
git checkout <branch> | Switches to another branch. |
git checkout -b <branch> | Creates and switches to a new branch. |
git merge <branch> | Merges another branch into the current branch. |
git log | Shows commit history. |
git diff | Shows changes between commits or files. |
git remote -v | Shows linked remote repositories. |
git fetch | Downloads updates without merging. |
git reset | Undoes changes (use carefully). |
git rm <file> | Deletes a file from the repository. |
git stash | Temporarily saves unfinished changes. |
But in these commands , most important one’s are :
git init
git init It is used to initializes a new Git repository in a folder. Like this you can initializes the git in Bash or VS Code where you want
git init
git add
git status is one of the most important Git commands. It tells you what is happening in your project right now. It tells you whether there is any update in program or not.
git status
git add
git add is used to move your changes to the staging area so they can be saved (committed). we can write this command in two ways :
git add basic.js(after git add write the name of file).git add .(This (.) means the all files in the folder).
git add basic.js
git add .
git commit
git commit is used to save your staged changes permanently in Git with a message.
After you add files using git add, git commit:
Saves those changes.
Creates a checkpoint in your project history.
Adds a message describing what you changed.
git commit -m "your message"
commit messages help you and others understand:
What was changed
Why it was changed
Good messages make your project easier to manage.
git log
git log is a command that shows the history of commits in your current branch. If Git is like a time machine for your code, then git log is the control panel that shows all your past stops—all the commits you’ve made.
When you run git log:
git log
Then it shows:
commit 9a1b2c3d4e5f6g7h8i9j
Author: Mohit Kumar <mohit@example.com>
Date: Tue Dec 31 2025
Added new feature to homepage
Local repository structure overview
When you initialize a Git repository (git init), Git creates a .git folder.
This folder is the brain of Git — it stores everything about your project’s history.

Commit History Flow
Think of Git as a time machine for your project. Every time you save your work with a commit, Git remembers it. The commit history is like a timeline of all your changes, and understanding it helps you navigate your project easily.

Conclusion
Git is more than just a version control system—it’s your project’s personal time machine. It helps you track every change, collaborate with others, and experiment freely without fear of losing work.
With Git, you can:
Save snapshots of your project with commits
Work on multiple features simultaneously using branches
Collaborate safely through remote repositories like GitHub
Navigate project history effortlessly with HEAD, log, and checkout
In short, Git brings order, safety, and flexibility to your development workflow. Whether you’re working solo or in a team, mastering Git gives you confidence and control over your code.
Pro Tip: Think of Git as your project’s storybook—every commit is a page, every branch is a chapter, and HEAD shows the page you’re currently reading. Keep writing, merging, and exploring!





