Version control is one of the most essential tools for any developer. Whether you’re a student, a hobbyist, or a professional, understanding Git and GitHub will make your life much easier.
This guide is written specifically for beginners — from zero knowledge to confidently using Git and GitHub in your daily work.
What is Git?
Git is a version control system that tracks changes to files over time. It allows you to:
- See the history of changes
- Revert to previous versions
- Collaborate with others without conflict
- Work on multiple features simultaneously
Git vs GitHub
| Git | GitHub |
|---|---|
| The actual version control software | A cloud platform for hosting Git repositories |
| Works locally on your computer | Allows sharing and collaboration online |
| Command-line tool | Web-based interface with additional features |
In short: Git is the engine. GitHub is the garage.
Why Was Git Created?
Git was created by Linus Torvalds in 2005 to manage the development of the Linux kernel. The Linux kernel had thousands of contributors worldwide, and existing version control systems couldn’t handle the scale. Git was built to be:
- Fast
- Distributed (everyone has a full copy)
- Branch-friendly
Why Every Developer Should Learn Git
- It’s a standard — Almost every tech company uses it
- Collaboration — Work with teams seamlessly
- Safety — Never lose your code again
- Portfolio — GitHub is your resume for developers
- Open source — Contribute to projects worldwide
Installing Git
Windows
- Download Git from git-scm.com
- Run the installer (default settings are fine)
- Open Command Prompt or Git Bash
Check Installation
git --version
You should see something like:
git version 2.40.0
Initial Configuration
Before using Git, you need to set your identity:
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
Check Your Configuration
git config --list
Creating a New Repository
Let’s say you have a folder called Project where your code lives.
cd Project
git init
Output:
Initialized empty Git repository
Your folder is now a Git repository!
Checking File Status
To see the current state of your files:
git status
If you see:
Untracked files:
It means Git hasn’t started tracking those files yet.
Adding Files to Git
Add All Files
git add .
Add a Specific File
git add index.html
This tells Git: “Please start tracking this file.”
Committing Changes
A commit is like a snapshot or checkpoint of your project.
git commit -m "Initial commit: homepage structure"
Why Commit Messages Must Be Clear
Good commit messages help you and your team understand:
- What changed
- Why it changed
- When to revert if something breaks
| Bad | Good |
|---|---|
fix stuff |
Fix login error when using special characters in password |
Connecting to GitHub
First, create a repository on GitHub:
https://github.com/yourusername/myproject
Then connect your local repository to GitHub:
git remote add origin https://github.com/yourusername/myproject.git
Check Your Remote Connection
git remote -v
First Push
Push your code to GitHub for the first time:
git push -u origin main
-usets the default upstream branch (you only need this once)- After this, you can simply use
git pushto send updates
Cloning a Repository
To download an existing repository from GitHub:
git clone https://github.com/yourusername/myproject.git
This creates a copy on your computer.
Pulling Updates
To get the latest changes from GitHub:
git pull
This downloads and merges updates from the remote repository.
Fetch vs Pull
| Git Fetch | Git Pull |
|---|---|
| Downloads updates but doesn’t merge them | Downloads and merges updates |
| Safe for inspection | Applies changes directly |
git fetch then git merge combined = git pull |
Faster for daily updates |
Think of fetch as “checking for new mail” and pull as “checking and opening the new mail.”
Working with Branches
Branches allow you to work on different features independently.
See All Branches
git branch
Create a New Branch
git branch feature-login
Switch to a Branch
git checkout feature-login
Or (modern way):
git switch feature-login
Create and Switch Simultaneously
git switch -c feature-login
Merging
After finishing work on a branch, merge it back to the main branch:
git checkout main
git merge feature-login
Viewing History
Full Log
git log
Compact Version
git log --oneline
Viewing Changes
See what’s different between your current files and the last commit:
git diff
Deleting Files
git rm file.txt
Renaming Files
git mv oldname.txt newname.txt
Restoring Files
Restore a File Not Yet Committed
git restore index.html
Undo a Commit
Soft Reset (keeps changes)
git reset --soft HEAD~1
Removes the commit but keeps your changes staged.
Hard Reset (discards changes)
git reset --hard HEAD~1
Removes the commit and discards all changes.
⚠️ Warning: Hard reset permanently removes uncommitted work!
Ignoring Files
Create a .gitignore file in your project root:
node_modules/
*.log
.env
These files will no longer be tracked by Git.
GitHub Desktop
For those who prefer a visual interface:
- Download GitHub Desktop
- Log in with your GitHub account
- Clone a repository
- Commit changes
- Push with a single click
All Git operations are available in a user-friendly GUI.
Using GitHub Web
You can also interact with GitHub directly in your browser:
- Create repositories
- Upload files
- Edit files online
- Commit directly from the browser
- Create releases
- Download source code
Important Terminology
| Term | Definition |
|---|---|
| Repository | A project folder tracked by Git |
| Commit | A snapshot of changes |
| Push | Upload commits to GitHub |
| Pull | Download commits from GitHub |
| Fetch | Check for updates without merging |
| Merge | Combine branches |
| Branch | An independent line of development |
| Fork | A copy of someone else’s repository |
| Clone | Download a repository to your computer |
| Remote | Connection to a GitHub repository |
| Origin | The default name for your remote |
| Main | The default primary branch |
| Pull Request | Request to merge changes into a project |
Daily Workflow Example
Here’s how a typical day looks:
Morning
↓
git pull (get latest updates)
↓
Start working
↓
git add . (stage your changes)
↓
git commit (save your work)
↓
git push (share your work)
↓
Done!
When to Use What
| Action | When to Use |
|---|---|
| Push | After completing work and committing |
| Pull | At the start of the day or when starting a new task |
| Branch | When working on a new feature or experiment |
| Merge | When finishing a feature and joining it to main |
| Fork | When you want to contribute to someone else’s project |
Conclusion
Git and GitHub are powerful tools that every developer should learn. They may seem intimidating at first, but with practice, they become second nature.
Start small. Make your first commit. Push your first project. Create your first branch.
The journey of a thousand lines of code begins with a single git init.
Happy coding!