As you grow in your tech journey, one tool you will definitely encounter early is Git. At first, it might feel confusing or even intimidating, but once you understand why it exists and how it works, it becomes one of the most powerful tools in your workflow.
In this article, we’ll cover:
- What Git is and why version control is important
- How to push code to GitHub
- How to pull code from GitHub
- How to track changes using Git
Let’s break it down step by step.
What Is Git and Why Is Version Control Important?
Git is a version control system. In simple terms, it helps you:
- Track changes in your code
- Save different versions of your project
- Collaborate with others without overwriting each other’s work
Imagine working on a project and accidentally deleting a file that worked perfectly yesterday. Without Git, that’s a nightmare. With Git, you can go back in time and restore previous versions.
Why Version Control Matters
Version control allows you to:
- See what changed, when, and by who
- Work on features safely
- Experiment without fear
- Collaborate with teams efficiently
GitHub, on the other hand, is a platform that hosts Git repositories online, making it easier to store, share, and collaborate on code.
Initial Setup (Quick Recap)
Make sure you have:
- Git installed
- A GitHub account
- SSH set up (as covered in the previous article)
Open your terminal using Ctrl + Alt + T.
Step 1: Initialize a Git Repository
Navigate to your project folder:
cd project-folder
Initialize Git:
git init
This creates a hidden .git folder that Git uses to track your project.
Step 2: Tracking Changes Using Git
Check Project Status
git status
This shows:
Untracked files
Modified files
Files ready to be committed
Add Files to Staging
To track all files:
git add .
Or add a specific file:
git add filename.py
Commit Your Changes
git commit -m "Initial project setup"
A commit is like saving a snapshot of your project at that moment.
Step 3: Push Code to GitHub
Create a Repository on GitHub
Log in to GitHub
Click New repository
Give it a name
Do not initialize with README
Copy the SSH repository URL
Connect Local Repo to GitHub
git remote add origin git@github.com:username/repository-name.git
Verify:
git remote -v
Push Your Code
git branch -M main
git push -u origin main
Your code is now live on GitHub
Step 4: Pull Code from GitHub
Pulling allows you to fetch and update your local code with changes from GitHub.
git pull origin main
This is especially important when:
Working with others
Switching between machines
Updating your local copy
Step 5: Viewing and Tracking Changes
View Commit History
git log
See File Changes
git diff
Quick Overview
git status
These commands help you understand what changed, what’s staged, and what’s committed.
A Typical Git Workflow
Here’s how things usually flow:
Make changes to your code
Check status
git status
- Add changes
git add .
- Commit
git commit -m "Describe what you changed"
- Push to GitHub
git push
Simple, repeatable, and powerful.
Final Thoughts
Git is not just a tool — it’s a safety net for your code. Once you get comfortable with pushing, pulling, and tracking changes, your confidence as a developer grows significantly.
If you’re just starting out, don’t rush mastery. Focus on understanding the basics and practicing regularly.
What’s Next?
Practice! Practice! Practice!
Top comments (0)