Git and GitHub Setup Guide: Version Control Basics
Git and GitHub are essential for any programmer. Git tracks changes to your code, and GitHub hosts your code online. They're not as complicated as they seem, and I'm going to show you how to get started.
This guide will get you set up with Git and GitHub. By the end, you'll be able to track your code changes and push to GitHub.
What is Git?
Git is version control software. It tracks changes to your files, lets you go back to previous versions, and helps you collaborate with others. Think of it like "Save" but way more powerful.
What is GitHub? GitHub is a website that hosts Git repositories online. It's like cloud storage for code, but with version control built in.
Step 1: Install Git
Windows:
- Go to git-scm.com
- Download Git for Windows
- Run the installer
- Use default options - they're fine
Mac:
- Git might already be installed. Check by opening Terminal and typing
git --version - If not installed, install Xcode Command Line Tools:
xcode-select --install - Or install via Homebrew:
brew install git
Linux:
sudo apt install git
Step 2: Configure Git
Tell Git who you are:
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
Use the same email you'll use for GitHub. This connects your local Git to your GitHub account.
Step 3: Create a GitHub Account
Sign up:
- Go to github.com
- Click "Sign up"
- Choose a username (you can't change it easily, so pick wisely)
- Verify your email
The free plan is fine for most people. You get unlimited public and private repositories.
Step 4: Create Your First Repository
On GitHub:
- Click the "+" icon → "New repository"
- Give it a name (like "my-first-project")
- Choose public or private
- Don't check "Initialize with README" (we'll do it manually)
- Click "Create repository"
You'll see instructions for connecting your local computer to this repository.
Step 5: Connect Local to GitHub
On your computer:
- Create a folder for your project
- Open Terminal/Command Prompt in that folder
- Initialize Git:
git init - Create a file (like
README.md) - Add and commit:
git add . git commit -m "First commit" - Connect to GitHub (use the URL from your repository page):
git remote add origin https://github.com/yourusername/repo-name.git git push -u origin main
It'll ask for your GitHub username and password. Use a personal access token instead of your password (GitHub doesn't accept passwords anymore). Create one at GitHub → Settings → Developer settings → Personal access tokens.
Basic Git Commands
Check status:
git status
Shows what files have changed.
Add files:
git add .
Stages all changes (prepares them to be committed).
Commit:
git commit -m "Describe what changed"
Saves a snapshot with a message.
Push:
git push
Uploads your commits to GitHub.
Pull:
git pull
Downloads changes from GitHub.
Your Workflow
Here's the typical workflow:
- Make changes to your files
git add .- Stage your changesgit commit -m "message"- Save a snapshotgit push- Upload to GitHub
Do this regularly. Don't wait until you have a million changes - commit often.
Common Mistakes
- Forgetting to commit: Changes aren't saved to Git until you commit them
- Bad commit messages: "Update" doesn't help. Write something like "Fix login bug" or "Add contact form"
- Committing too much: Make smaller, more frequent commits
- Forgetting to push: Commits are local until you push. If your computer dies, you lose them
- Not pulling before pushing: If someone else made changes, pull first, then push
Using GitHub's Web Interface
You can do a lot directly on GitHub:
- Create files: Click "Add file" → "Create new file"
- Edit files: Click on a file, then the pencil icon
- See history: Click on a file, then "History" to see all changes
- Create branches: Click the branch dropdown, type a name, create branch
For simple changes, the web interface is fine. For bigger projects, use the command line.
Pro Tip: Commit often. Every time you finish a small feature or fix a bug, commit it. Small, frequent commits are way better than one huge commit at the end of the day. They're easier to understand, easier to undo if something goes wrong, and easier to review.
Common Questions
What's the difference between Git and GitHub?
Git is the software that does version control on your computer. GitHub is the website that hosts your repositories online. You use Git commands to interact with GitHub.
Do I need to know programming to use Git?
Not really. Git works with any files - code, documents, images, whatever. But it's most useful for code projects.
Is GitHub free?
Yes! Free accounts get unlimited public and private repositories. You only pay if you need advanced features for teams.
Start Using Git and GitHub
Git and GitHub are set up. Create a repository, make some changes, commit them, and push to GitHub. The more you use it, the more natural it becomes. Once you're used to it, you'll wonder how you lived without version control.