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 is used because it 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 go back 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 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
You create it using:
git init
π¦ Commit
A commit is a snapshot of your code at a specific point in time.
Think of a commit as: "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 help you experiment without breaking main code.
π HEAD
HEAD points to your current position in Git history.
Simply put: 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
- .git folder: 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 new
- Which files are modified
- What is staged for commit
π This is the most used Git command.
πΉ git add
Adds files to the staging area.
git add filename.txt
Add everything:
git add .
π Staging means "I want to include this in the next commit".
πΉ git commit
Creates a snapshot of staged changes.
git commit -m "Add initial project files"
βοΈ Always write clear and meaningful messages.
β Bad:
git commit -m "changes"
β
Good:
git commit -m "Add login page UI"
πΉ git log
Shows commit history.
git log
You'll see:
- Commit hash
- Author
- Date
- Commit message
This helps you understand project history.
πΉ git branch
List all branches:
git branch
Create a new branch:
git branch feature-login
Switch branch:
git checkout feature-login
(or modern way)
git switch feature-login
πΉ git merge
Merge one branch into another.
git merge feature-login
π Combines work from different branches.
π A Simple Git Workflow (From Scratch)
Let's see a real beginner workflow.
Step 1: Create a project
mkdir my-project
cd my-project
Step 2: Initialize Git
git init
Step 3: Create a file
touch index.html
Step 4: Check status
git status
Step 5: Stage the file
git add index.html
Step 6: 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 status often
β 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! π
=


Top comments (0)