How to Learn Git and GitHub as a Beginner
General • Tools & Setup • 7 min read
A practical guide to Git and GitHub. Learn the essential commands, create your first repository, and start collaborating with other developers.
How to Learn Git and GitHub as a Beginner
Git and GitHub are essential tools for every developer. Git tracks changes in your code, and GitHub hosts your code online. Together, they make collaboration possible. Here's how to get started.
What is Git?
Git is a version control system. Imagine writing an essay and saving different versions: essay_v1.doc, essay_v2.doc, essay_final.doc, essay_final_real.doc. Git does this automatically for your code. You can go back to any point in your project's history.
What is GitHub?
GitHub is a website that hosts your Git repositories online. It's like Google Drive for code. You can share your projects, collaborate with others, and contribute to open-source projects.
Installing Git
Installing Git is straightforward:
- Go to git-scm.com
- Download the installer for your operating system
- Run the installer with default settings
- Open your terminal and type
git --versionto verify
Essential Git Commands
You only need a handful of commands to start. Here are the ones you'll use daily:
# Create a new repository
git init
# Add files to staging area
git add .
# Commit your changes
git commit -m "Your message here"
# Push to GitHub
git push origin main
# Pull latest changes
git pull origin main
# Clone an existing repository
git clone https://github.com/user/repo.git
Your First Git Project
Let's create your first repository step by step:
- Create a new folder on your computer
- Open terminal in that folder
- Run
git initto initialize a repository - Create a file (like index.html)
- Run
git add .to stage the file - Run
git commit -m "First commit" - Create a repository on GitHub
- Run
git remote add origin [URL] - Run
git push -u origin main
Branching
Branches let you work on features without affecting the main code. Think of it as a parallel universe where you can experiment safely.
# Create a new branch
git branch feature-login
# Switch to that branch
git checkout feature-login
# Merge it back to main
git checkout main
git merge feature-login
Common Mistakes Beginners Make
- Not committing often — Commit every small change, not once a week
- Bad commit messages — Write "Fixed login bug" not "stuff"
- Not using .gitignore — Never commit sensitive files like passwords
- Forgetting to pull — Always pull before you start working
Note: Git has a learning curve, but you only need the basics to start. Practice with a personal project, and the commands will become second nature within a week.