Advertisement

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:

  1. Go to git-scm.com
  2. Download Git for Windows
  3. Run the installer
  4. Use default options - they're fine

Mac:

  1. Git might already be installed. Check by opening Terminal and typing git --version
  2. If not installed, install Xcode Command Line Tools: xcode-select --install
  3. 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:

  1. Go to github.com
  2. Click "Sign up"
  3. Choose a username (you can't change it easily, so pick wisely)
  4. 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:

  1. Click the "+" icon → "New repository"
  2. Give it a name (like "my-first-project")
  3. Choose public or private
  4. Don't check "Initialize with README" (we'll do it manually)
  5. Click "Create repository"

You'll see instructions for connecting your local computer to this repository.

Step 5: Connect Local to GitHub

On your computer:

  1. Create a folder for your project
  2. Open Terminal/Command Prompt in that folder
  3. Initialize Git:
    git init
  4. Create a file (like README.md)
  5. Add and commit:
    git add .
    git commit -m "First commit"
  6. 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.

Advertisement

Your Workflow

Here's the typical workflow:

  1. Make changes to your files
  2. git add . - Stage your changes
  3. git commit -m "message" - Save a snapshot
  4. git 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.

Advertisement