Git for Beginners: Basics and Essential Commands

Table Of Contents
What is Git
Why Git is Used
Git Basics and Core Terminologies
Common Git Commands
Have you ever edited a file Google Docs, saved it, and then wished you could go back to the previous version?
Or maybe you tried something new in your project and suddenly everything broke—and you didn’t remember what the “working” version looked like?
In tools like Google Docs we have Version History. You can see the different editing there like what time and which day the page is edited and the data also.
That is exactly the kind of problem Git solves for developers.
It remembers what your project looked like yesterday, last week, or even months ago. You can experiment freely, make mistakes, and always come back.
What is GIT?
Git is a “Distributed Version Control system” .
Version Control means it keeps track of the changes we made to the code and tracking who made the changes.
Distributed means it is distributed in the group like every developer has a full copy of project history in their computer.
Now let’s understand a bit about “GitHub”
Git works locally on your computer—it tracks changes, saves versions, and lets you experiment safely. But GitHub(online service) is a cloud-based platform where you can store your Git projects online. GitHub allows developers to collaborate, share code, review changes, and back up their work. It also makes teamwork easy by letting multiple people work on the same project from different places.
Why GIT is used?
It helps to track every change in your project, so we always know what changed and when .
It lets you undo mistakes safely. If something breaks, you can go back to a previous working version.
It makes teamwork easy to manage . Multiple people can work on the same project without overwriting each other’s work.
Git is used because projects requirements will keep on changing. Code is written, edited, deleted, and improved every day. So system like GIT helps to manage.
Git Basics and Core Terminologies
Lets understand some of the Core Terminologies in GIT.
Repository(Repo) : A repository is a storage space where your project's files and their history are kept. It can be local (on your computer) or remote (on a server like GitHub).
Commit : A commit represents a snapshot of your repository — like a version of your project at a particular time . Each commit has:
A unique identifier
A commit message
A record of changes
Clone : Cloning is the process of creating a copy of a remote repository on your local machine.
Branch : Branch is like a seperate copy of the repository where we work on feature development, bug fixes etc. Branches allow you to work on different parts of a project without affecting the main branch.
Head : Head points to the current commit you are working on.
Working Directory: The directory that contains all the files that are tracked by Git.
Staging Area (Index): A place where you can see changes before committing them.
Repository (HEAD): The Git repository is the place where the files are stored. Git Repository has a directory structure
The diagram below shows how your files move from your computer to Git’s history.

GIT Basic Commands
- git init : Creates a new .git folder in your current directory. This turns any folder into a Git repository
Below I have attached screenshots of how to create a new repository and clone it and then Initialize the empty repository.




git clone : git clone is the command used to download a copy of the repository on to the local machine. I have shown above how to create a repo and then cloning the empty repository. Likewise you can clone any repository on the internet onto your local machine. This will create an exact copy of the existing Git repository with a complete history
git status : This command is used to display the state of the working directory and the staging area. This shows which files are being tracked by git.
git add : This command we use in the staging area. In this stage you can select the files we would like to commit. In the below diagram I have used “git add .” means to stage the changed files to commit.
git commit : Commit command is used to save the files in the staging area with the message , all saved history can be found with the given message name.
git push: Push command is used to add the commits from local repository to the remote repository. Once pushed others will be able to see those changes in the GitHub.
git pull : Pull command is used to get the changes which are present in the remote repo, It helps to have all the latest code from remote repo on to your local repo.
git log : This command is used to view the history of the commits in the local repo.
git branch : A branch creates a separate workspace from the main repository so you can work safely.
It is a copy of the current code where you can make design changes, fix bugs, or add new features without affecting the main branch.
Once your work is complete and tested, you can merge it back into the main branch.

In the below screenshot I have created a new branch and checked out into that new branch. You can find out in the bottom left .

you can see a complete Git flow in action — a file is staged, committed with a message, pushed to GitHub, and finally a new branch is created for future work.
This is how you use Git in projects every day.