Git for Beginners: Basics and Essential Commands 🚀
Source: Dev.to
Introduction
If you are starting your journey as a developer, you will hear the word Git everywhere.
Job descriptions mention it, open‑source projects require it, and almost every team uses it daily.
But what exactly is Git? And why is it so important?
This article explains Git from scratch, in simple words, with beginner‑friendly examples and commonly used commands.
📌 What is Git?
Git is a distributed version control system.
That sounds complex, so let’s simplify it.
👉 Git helps you track changes in your code over time.
It remembers:
- What changed
- When it changed
- Who changed it
…and lets you go back to older versions if something breaks.
Think of Git like a time machine for your code.
Instead of saving files like:
project_v1
project_v2
project_final
project_final_real
Git keeps everything organized and clean.
We’ve all been there! Git saves us from this chaos.
🤔 Why Git is Used
Git solves many real problems developers face.
1️⃣ Track Code History – You can see what changed and why it changed.
2️⃣ Work Without Fear – Made a mistake? You can revert to a previous version easily.
3️⃣ Collaboration – Multiple developers can work on the same project without overwriting each other’s code.
4️⃣ Industry Standard – Almost every company and open‑source project uses Git with platforms like:
- GitHub
- GitLab
- Bitbucket
👉 Learning Git is non‑negotiable for developers.
🧠 Git Basics and Core Terminologies
Before diving into commands, let’s understand the basic concepts.
📁 Repository (Repo)
A repository is a folder that Git tracks. It contains:
- Your project files
- Git’s history and metadata
Create one with:
git init
📦 Commit
A commit is a snapshot of your code at a specific point in time. Think of it as a “save point with a message.”
Each commit has:
- A unique ID (hash)
- Author
- Date
- Message explaining the change
🌿 Branch
A branch lets you work on features independently.
main(ormaster) → default branch- Feature branches → new ideas or fixes
Branches let you experiment without breaking the main code.
📍 HEAD
HEAD points to your current position in Git history. In simple terms: HEAD = “where you are right now.”
Usually, HEAD points to the latest commit of the current branch.
📊 Understanding Git Workflow
Here’s how Git organizes your work:

Three main areas:
- Working Directory – Where you make changes.
- Staging Area – Where you prepare changes for commit.
- Repository – Where Git permanently stores commits.
🗂️ Git Repository Structure

Your local repository consists of:
- Working Directory – Your actual project files.
.gitfolder – All Git metadata and history.- Remote Repository – GitHub/GitLab (optional).
🛠 Common Git Commands (With Examples)
Let’s learn Git commands by actually using them.
🔹 git init
Initializes Git in your project folder.
git init
Creates a hidden .git folder that Git uses to track everything.
🔹 git status
Shows the current state of your repository.
git status
It tells you:
- Which files are untracked, modified, or staged.
- If you have any commits pending to be pushed.
🔹 git add
Stages changes for the next commit.
git add # stage a specific file
git add . # stage all changes in the current directory
🔹 git commit
Records a snapshot of the staged changes.
git commit -m "Your descriptive commit message"
🔹 git log
Shows the commit history.
git log
Add --oneline for a compact view:
git log --oneline
🔹 git branch
Lists, creates, or deletes branches.
git branch # list all local branches
git branch # create a new branch
git -d # delete a branch
🔹 git checkout
Switches to another branch or restores files.
git checkout # switch branches
git checkout # discard changes in a file
🔹 git merge
Integrates changes from another branch into the current one.
git merge
🔹 git push
Uploads local commits to a remote repository.
git push origin
🔹 git pull
Fetches and merges changes from the remote repository.
git pull origin
🎉 Wrap‑Up
Git is an essential tool for every developer. By mastering the basics—repositories, commits, branches, and the core workflow—you’ll be ready to collaborate efficiently, keep a clean project history, and avoid the pitfalls of “code chaos.”
Start experimenting with the commands above, and soon Git will feel like a natural extension of your development workflow. Happy coding!
Git Basics Cheat‑Sheet
❓ What’s new / modified / staged?
- New files – files that don’t exist in the repository yet.
- Modified files – files that have been changed since the last commit.
- Staged files – files you’ve added to the index (the staging area) and are ready to be committed.
📌 Staging means “I want to include this in the next commit”.
🔹 git add
Add files to the staging area.
# Add a single file
git add filename.txt
# Add everything in the current directory
git add .
🔹 git commit
Create a snapshot of the staged changes.
git commit -m "Add initial project files"
✔️ Best practice: Write clear, meaningful commit messages.
Bad example
git commit -m "changes"
Good example
git commit -m "Add login page UI"
🔹 git log
Show the commit history.
git log
Typical output includes:
- Commit hash
- Author
- Date
- Commit message
🔹 git branch
Manage branches.
# List all branches
git branch
# Create a new branch
git branch feature-login
# Switch to a branch (old way)
git checkout feature-login
# Switch to a branch (modern way)
git switch feature-login
🔹 git merge
Combine changes from one branch into another.
git merge feature-login
📌 Merging integrates work from different branches.
🔄 A Simple Git Workflow (From Scratch)
-
Create a project
mkdir my-project cd my-project -
Initialize Git
git init -
Create a file
touch index.html -
Check status
git status -
Stage the file
git add index.html -
Commit changes
git commit -m "Add initial HTML file"
🎉 Congratulations! You just created your first Git commit.
😄 Git Reality Check
💡 Tips for Beginners
- ✅ Run
git statusoften. - ✅ Commit small, meaningful changes.
- ✅ Write clear commit messages.
- ✅ Don’t fear breaking things—Git has your back.
- ✅ Practice with small projects.

🎯 Conclusion
Git might seem intimidating at first, but once you understand the basics, it becomes second nature.
Start with these commands, practice regularly, and soon you’ll be managing complex projects with confidence!
What’s your biggest Git challenge? Drop a comment below! 👇