Beginner's Guide to Git and GitHub
Git and GitHub are two of the most important tools every developer should learn. Whether you're building personal projects, contributing to open-source software, or working with a team, understanding Git and GitHub will make your workflow more organized and professional.
If you've ever wondered "What's the difference between Git and GitHub?" or "Where do I even start?", this guide is for you.
What Is Git?
Git is a distributed version control system that tracks changes made to your files over time.
Think of Git as a time machine for your project. Every time you save important progress, Git records a snapshot that you can return to later.
With Git, you can:
- Track every change you make
- Undo mistakes
- Work on new features without affecting your main project
- Collaborate with other developers
- Keep a complete history of your project
What Is GitHub?
GitHub is a cloud platform that hosts Git repositories.
While Git manages your project's history on your computer, GitHub stores it online so you can:
- Back up your code
- Share projects
- Collaborate with others
- Review code changes
- Contribute to open-source projects
Simply put:
- Git = Version Control
- GitHub = Online Hosting for Git Repositories
Installing Git
Windows
Download Git from:
Run the installer using the default settings.
Linux
Ubuntu/Debian
sudo apt update
sudo apt install git
Arch Linux
sudo pacman -S git
Fedora
sudo dnf install git
macOS
Using Homebrew:
brew install git
Verify Installation
Open a terminal and run:
git --version
Example:
git version 2.50.1
Configure Git
The first thing you should do is tell Git who you are.
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
Check your settings:
git config --list
Creating Your First Repository
Create a project folder.
mkdir my-project
Move into it.
cd my-project
Initialize Git.
git init
Output:
Initialized empty Git repository
Your project is now being tracked by Git.
Understanding the Git Workflow
Git mainly works in three stages:
Working Directory
↓
Staging Area
↓
Repository
Working Directory
Where you edit your files.
Staging Area
Where you choose which changes should be saved.
Repository
Where Git permanently stores snapshots called commits.
Checking Repository Status
Use:
git status
This command tells you:
- New files
- Modified files
- Deleted files
- Files ready to commit
You'll probably use this command hundreds of times.
Adding Files
Track a specific file:
git add index.html
Track every changed file:
git add .
Creating Your First Commit
Once files are staged:
git commit -m "Initial commit"
A commit is simply a saved snapshot of your project.
Write meaningful commit messages.
Good:
Add login page
Better than:
Update
Viewing Commit History
git log
Compact version:
git log --oneline
Example:
3f8b9b4 Initial commit
9c2ab71 Add README
Creating a README
Create:
README.md
Example:
# My Project
This is my first Git project.
The README explains what your project does.
Ignoring Files
Some files should never be tracked.
Create:
.gitignore
Example:
node_modules/
.env
build/
*.log
Git will ignore these files.
Branches
A branch lets you work on new features without affecting the main project.
Create a branch:
git branch feature-login
Switch to it:
git checkout feature-login
Or both together:
git checkout -b feature-login
View branches:
git branch
Merging Branches
Switch back:
git checkout main
Merge:
git merge feature-login
Now your new feature becomes part of the main branch.
Connecting to GitHub
Create a new repository on GitHub.
Then connect your local project.
git remote add origin https://github.com/username/my-project.git
Verify:
git remote -v
Uploading Code
Push your commits:
git push -u origin main
Future pushes:
git push
Downloading Changes
Fetch the latest updates:
git fetch
Download and merge:
git pull
Cloning a Repository
Instead of downloading ZIP files:
git clone https://github.com/username/project.git
Move inside:
cd project
Common Git Commands
| Command | Purpose |
|---|---|
git init |
Initialize repository |
git status |
Check repository status |
git add . |
Stage all changes |
git commit -m "message" |
Save changes |
git log |
View history |
git branch |
List branches |
git checkout branch |
Switch branch |
git merge |
Merge branches |
git pull |
Download updates |
git push |
Upload commits |
git clone |
Download repository |
Best Practices
- Commit often with meaningful messages.
- Use branches for new features.
- Keep your
README.mdupdated. - Add a
.gitignorefile early. - Pull before pushing to avoid conflicts.
- Never commit passwords, API keys, or secrets.
Common Beginner Mistakes
❌ Forgetting to commit changes
❌ Writing commit messages like "fix"
❌ Working directly on the main branch for everything
❌ Forgetting to pull before pushing
❌ Accidentally committing sensitive files
Quick Workflow Example
git init
git add .
git commit -m "Initial commit"
git remote add origin https://github.com/username/project.git
git push -u origin main
For everyday development:
git add .
git commit -m "Describe your changes"
git push
Conclusion
Learning Git and GitHub is one of the best investments you can make as a developer. While the commands may seem intimidating at first, they quickly become second nature with regular practice.
Start with the basics—initialize a repository, make commits, create branches, and push your code to GitHub. As you gain experience, you'll discover more advanced features like pull requests, rebasing, and automated workflows. Mastering these tools will make you a more confident and efficient developer, whether you're working solo or collaborating with a team on projects of any size.