Git for Beginners: Basics and Essential Commands
Source: Dev.to

Introduction
If you are learning web development, sooner or later you will hear the sentence:
“Push your code to GitHub.”
But before GitHub there is Git.
Git is not just another tool; it is the foundation of software development. Almost every company, open‑source project, and developer uses Git daily.
In this article we will cover the basics of Git and the commands you’ll use in day‑to‑day work.
What is Git?
Git is a distributed version control system. It gives your code a memory.
- Track changes in your code
- Save different versions of your project
- Work with other developers without overwriting each other’s work
- Go back in time if something breaks
Use of Git
Before Git, developers relied on:
- Pendrives
- Email attachments
- Shared folders
- Files named
final_1,final_2,last_final, etc.
These practices caused:
- Lost code
- Overwritten changes
- No history
- No collaboration
Version control solves all of these problems. Git:
- Keeps a full history of changes
- Shows who changed what and when
- Allows collaboration with a team
- Makes mistakes reversible
That’s why everyone loves Git.
Git Basics and Core Concepts
1. Repository (Repo)
A repository is just a folder that Git tracks. It contains:
- Your project files
- Git history
- Git configuration
When you run git init in a folder, Git creates the necessary files to track all changes.
2. Commit
A commit is a snapshot of your code at a specific point in time. Each commit includes:
- A unique ID (SHA‑1 hash)
- Author name
- Date & time
- A message describing the change
3. Branch
A branch is an independent line of development.
- Main branch – stable code (often
mainormaster) - Other branches – experiments, features, fixes
4. HEAD
HEAD is a pointer to the current commit you are working on. It shows where you are in the project’s history.
5. Git Workflows

Git works with three main areas:
- Working directory – your current files
- Staging area – files prepared for the next commit
- Repository – the permanent history
Installing Git
- Windows: Download from git-scm.com
- macOS:
brew install git - Linux:
sudo apt install git
After installation, verify the version:
git --version
Common Git Commands
1. git init
Initialize a new Git repository.
git init
2. git status
Show the current status of your project (modified, staged, untracked files).
git status
3. git add
Add files to the staging area.
git add # add specific files
git add . # add everything
Staging means: “I want to include these changes in the next commit.”
4. git commit
Save staged changes permanently to the repository.
git commit -m "Your meaningful commit message"
5. git log
Display the commit history.
git log
You can see the commit hash, author, date, and message.
6. git branch
List all branches.
git branch
Create a new branch:
git branch <branch-name>
7. git checkout
Switch to another branch.
git checkout <branch-name>
8. git checkout -b
Create and switch to a new branch in one step.
git checkout -b <new-branch-name>
Why Every Developer Should Learn Version Control
- Work confidently in teams
- Debug faster
- Build professional habits
- Prepare for jobs and internships
Conclusion
Git is not just a tool; it is:
- A safety net for your code
- A collaboration system
- A time machine that lets you travel back to any previous state
Start using Git today and make your development workflow more reliable and collaborative.