If you are learning programming or working with code, you will hear the word Git everywhere. Git can feel confusing at first, but once you understand the basics, it becomes one of the most powerful tools in your developer toolkit.
This article explains:
What Git and version control are
How Git tracks changes
How to push and pull code
A simple Git workflow you can follow confidently
You don't need any prior experience.
1. What Is Version Control?
Version control is a system that helps you track changes made to files over time.
Think of it like this:
You wrote some code today
Tomorrow you change it
Next week, something breaks, and you want the old version back
Version control solves this problem by:
Keeping a history of every change
Allowing you to go back to previous versions
Making it easy for multiple people to work on the same project
2. What Is Git?
Git is a version control system used to track code changes.
Key things Git does:
Tracks file changes
Records who made a change and when
Allows collaboration without overwriting each other’s work
Works locally on your computer (even without internet)
Git is different from GitHub:
Git → the tool
GitHub / GitLab / Bitbucket → online platforms that store Git repositories
3. What Is a Repository?
A repository (repo) is a project folder that Git tracks.
It contains:
Your project files (code, images, docs)
A hidden .git folder that stores version history
There are two types:
- Local repository → on your computer
- Remote repository → online (for example, on GitHub)
4. How Git Tracks Changes
Git tracks changes in three main areas:
1. Working Directory
This is where you edit files normally. Example:
index.html
style.css
At this stage, Git sees changes but hasn’t recorded them yet.
2. Staging Area
The staging area is where you prepare changes before saving them permanently.
Command:
git add filename
Or add everything:
git add .
Think of this as saying:
"These are the changes I want Git to remember."
3. Commit History
A commit is a snapshot of your project at a specific time.
Command:
git commit -m "Describe what changed"
A commit includes:
- The changes
- Your message
- Date and author
Git Change Flow (Very Important)
Edit files Stage changes Commit
5. Installing Git
Check if Git is installed:
git --version
If not installed:
- Windows: Download from git-scm.com
- macOS: Install via Homebrew or Xcode tools
- Linux: Use your package manager
6. Creating Your First Git Repository
Navigate to your project folder:
cd my-project
Initialize Git:
git init
Now your folder is a Git repository.
7. Checking File Status
Use this command often:
git status
It tells you:
- Which files are modified
- Which files are staged
- What is ready to commit
8. Making Your First Commit
Step 1: Add files to staging
git add .
Step 2: Commit changes
git commit -m "Initial project setup"
You have now saved your first version.
9. Understanding Push and Pull
What Is Push?
Push sends your local commits to a remote repository (like GitHub).
Example:
git push origin main
Meaning:
- Push → send changes
- origin → remote repository
- main → branch name
You use push when:
- You want to upload your work
- You want others to see your changes
What Is Pull?
Pull downloads the latest changes from the remote repository to your local machine.
Example:
git pull origin main
You use pull when:
- Someone else updated the code
- You want the latest version before working
Important Rule
Always pull before you start working to avoid conflicts.
10. Understanding Branches (Beginner Level)
A branch is a separate line of development.
- Main (or master) → stable code
- Feature branches → new features or experiments
Create a new branch:
git branch feature-login
Switch to it:
git checkout feature-login
Or both in one command:
git checkout -b feature-login
Branches let you:
- Experiment safely
- Avoid breaking main code
- Work in parallel with others
11. A Simple Daily Git Workflow
Here is a beginner-friendly workflow you can follow every day:
- Pull latest changes
git pull origin main
Make code changes
Check status
git status
- Stage changes
git add .
- Commit changes
git commit -m "Add login validation"
- Push to remote
git push origin main
12. Viewing Commit History
See past commits:
git log
This helps you:
- Understand project history
- Identify when bugs were introduced
- Revert changes if needed
13. Common Beginner Mistakes
Forgetting to commit changes
Writing unclear commit messages
Not pulling before pushing
Editing directly on the main branch
Panicking when seeing merge conflicts (they are normal)
14. Why Git Is Essential
Git is used by:
- Solo developers
- Large companies
- Open-source projects
It helps you:
- Work confidently
- Recover from mistakes
- Collaborate professionally
- Build real-world projects
15. Final Thoughts
Git may feel overwhelming at first, but you only need a few commands to be productive:
git status
git add
git commit
git push
git pull
Master these, and you already understand the core of Git and version control.
The best way to learn Git is to use it daily. Make mistakes, explore, and keep practicing.
Top comments (0)