Git for Beginners: Basics and Essential Commands

What is Git?
Git is a Version Control System (VCS). In simple language, Git is a tool that helps us save and manage the history of our code, just like a history book keeps records of past events. It allows developers to keep track of every change made in the project so nothing is lost.
Git is especially useful when many people work on the same project. Each person can write code, make changes, and later combine their work without confusion.
Important points about Git
Maintains the history of code changes
Keeps a track record of who changed what and when
Allows multiple people to work together on the same project
Helps to restore old versions if something goes wrong
Makes collaboration easy in software development
How to Use Git : Basics and Essential Commands
Before using Git commands, you must first install Git on your computer. Git is free software that works on Windows, Linux, and macOS.
Check if Git is installed
git --version
#If a version appears, Git is installed.
Initialize Git in the project
git init
#This converts your normal folder into a Git repository.
#Creates a hidden .git folder where Git stores history
Check file status
git status
#This shows:
# new files
# modified files
# files ready to commit
Add files to staging area
git add file_name
#Staging means: I am ready to save these changes.
#Only ready to save changes, not actually saved yet.
git add .
#this command use for add all files at once in staging area.
Commit your changes
git commite -m "Write a clear message about the changes"
#Commit means saving a snapshot of your "code history".
See commit history
git log
#Shows all commits with author, date, and message.
git log --oneline
#Short version
See differences before commit
git diff
#Shows what exactly changed in files.
Unstage a file (remove from staging area)
git reset file_name
#Removes the file from staging area only
#Changes in the file are not deleted
Undo last commit (without deleting changes)
git reset --soft HEAD~1
#Removes last commit
#BUT keeps your changes staged
#Nothing is deleted
Dangerous: deletes changes
This deletes your unsaved work permanently
git reset --hard
#Removes commits
#Removes staged files
#Removes working directory changes
#Everything goes back to last commit
Safest way to undo a commit
git revert <commit_id>
#Does NOT delete history
#Creates a new commit that cancels previous commit
Conclusion
Git is a basic Version Control System (VCS) that maintains the history of files and tracks all changes. It allows users to revert and manage changes in a single file or the entire project.