Git for Beginners: Basics and Essential Commands
Learn what is Git and why it is indispensable in modern ecosystems

I am a problem solver and a full-stack developer. I love to write and share my knowledge. My wish is to learn and help others learn at the same time. Hoping to make a difference in the tech world.
What is Git
Git is a distributed version control system.
Version Control System (VCS) - A tracker which tracks changes and stores them somewhere. Git tracks changes and stores them inside the
.gitfolder.The
.gitfolder has many other roles as well besides just trackingIt tracks changes made only on a local system. To track changes globally we need a
VCS Remotewhich would hostGitand allow collaboration. e.g. GitHub, Gitlab, Bitbucket, etc.
Basically, Git is nothing but a code tracker that tracks all modifications like changes, updates, creations, deletions and stores all of that in a hidden local directory, without the need of any manual tracking. However, it does not support any collaboration feature and for that we would need a VCS Remote which would host Git in a public domain and allow to usage, i.e. a Single Source of Truth setup.
Why Git is used
Tracking - Helps to automate tracking of changes in your project repo.
Rollback - Git’s internal design uses linked list architecture, allowing to go back versions if required.
Efficient - Git automatically tracks updates without any need of manual intervention, making the process seamless.
Git Basics and Core Terminologies
Now that we know what and why of Git, let’s delve a bit about how. Going forward these are some core jargons that you should know:
repository- your current working directorycommit- saved changes that have been tracked also known as asnapshotbranch- the current working tree you are on, a collection of commits made by u. The default branch as of today ismainHEAD- an indicator of the current branch. Analogy - think about the head pointer in a linked list.Staging area- Any file whose changes have been tracked but not saved are said to reside in the staging area.Untracked (U)- Changes have not been tracked yetModified (M)- Changes have been tracked but more changes have been done after that leading to a mismatch between the last tracked file and the current file.refs- a directory inside.gitcontaining a reference to theHEADcommit_id- a link containing reference to previous commit (just like the address part of a LinkedList)SHA- commit_ids are generally hashed in these algorithms
Common Git Commands
git init- Initializes git in your current directory (internally -.gitrepo is generated)git add <filename>- Tracks changes made and sends your file to thestaging areagit add .- Stages all files in the current directory
git commit -m “message”- Saves the tracked changesgit log- Shows history of all previous commitsgit status- Shows if there is any modification or notgit revert <commit_id>- Makes a new commit which does the opposite of the previous commitgit reset --hard <commit_id>- Pointer moves to previous commit and latest commit is deleted making previous commit the latest (Use with caution - usegit revertif needed)--hard- DO NOT FORGET to add this flag or you might accidentally delete important commits
git branch- Shows current branch
Advanced Essential Commands
git commit -am “message”- stages and commits all files in the working directory in one gogit log --oneline- Shows history in one-line, better readability than original commandgit cat-file -p <commit_id>- Shows details of that commit. It generally has 3 sections - owncommit_id, previous commit’scommit_id,author, etc. Generally used when we need to see the content of a particular commit.
Developer Workflow

This is the whole process through which changes are tracked by Git (simplified)
Local Repository Structure Overview (High Level View)
my-project/
├── .git/ ← the repository (Git’s brain)
│ ├── HEAD
│ ├── config
│ ├── index
│ ├── objects/
│ ├── refs/
│ │ ├── heads/
│ │ └── tags/
│ └── logs/
└── src/
└── main.c
Commit History Flow

Every commit is basically like nodes in a linked list which contains the address of the previous commit. The commit_id is hashed using SHA algorithms, and every branch is like a separate linked list.
Git is like any other software, but its unique use case makes it an indispensable tool in modern ecosystems. Knowing how to use Git is considered a fundamental skill that any developer should know as you will use it 99% of the time.




