When you first hear about Git, it sounds intimidating, but once you understand why Git exists and how the basic commands work, everything starts to make sense.
This article will walk you through:
- What version control is (in layman’s language)
- How Git tracks changes
- How to push and pull code
- The most common Git commands
What Is Version Control?
Remember working on assignments and saving your file as:
project_final.docxproject_final_v2.docxproject_final_really_final.docx
Now imagine doing this with code, across months or years, with several people.
That’s where version control comes in.
Version control helps you:
- Track changes over time
- Go back to older versions if something breaks
- Collaborate with others without tampering with each other’s work
- Know who changed what and when
Git is the most popular version control system.
What Is Git?
Git is a tool that:
- Runs on your computer
- Tracks changes in your project files
- Lets you save “snapshots” of your work
- Connects your local project to online platforms like GitHub or GitLab
Key Git Concepts
1. Repository (Repo)
A repository is your project folder that Git is tracking.
- Local repository → on your computer
- Remote repository → online (e.g. GitHub)
2. Working Directory
This is where you write and edit your code.
- Changes exist here but they are not saved yet
3. Staging
Before saving changes, Git asks:
“Which changes do you want to include?”
The staging area is where you prepare changes before saving them.
4. Commit
A commit is a saved snapshot of your project.
Each commit:
- Has an ID (identifier)
- Has a description of the change
- Can be restored later
Installing Git
Check if Git is installed:
git --version
If not:
- Linux
sudo apt install git
- macOS
brew install git
- Windows
Download from https://git-scm.com
Starting a Git Project
Initialize Git
Inside your project folder:
git init
This tells Git to start tracking your project.
Check Repository Status
git status
This command shows:
- Modified files
- Staged files
- What Git is waiting for
Tracking Changes in Git 📝
Step 1: Make Changes
Edit or create a file:
project1.py
Git detects the change but hasn’t saved it yet.
Step 2: Stage Changes
git add project1.py
Or stage all changes:
git add .
Step 3: Commit Changes
git commit -m "Add python file"
This saves a snapshot of your work.
💡 Tip: Write commit messages as clear explanations for humans.
Understanding Push and Pull 🔄
Local vs Remote Repositories
- Local → your computer
- Remote → GitHub / GitLab
Pushing Code (Upload Your Work)
Push sends your commits to the remote repository:
git push origin main
After pushing:
- Your code is online
- Others can access it
- Your work is backed up
Pulling Code (Download Updates)
Pull gets the latest changes from the remote repository:
git pull origin main
You should pull everytime before starting work
A Typical Git Workflow 🔁
git pull
# make changes
git status
git add .
git commit -m "Describe what you changed"
git push
This is the basic Git loop you'll use daily.
Viewing Change History
git log
This shows:
- Commit history
- Authors
- Timestamps
- Commit messages
Final Thoughts 🌱
Git might feel overwhelming at first, but you get a hold of it.
Focus on these commands:
git statusgit addgit commitgit pushgit pull
With practice, you'll become a Git Guru.
Happy coding! 🚀
Top comments (0)