Lesson 0: Setting Up Git and GitHub

What You'll Learn

In this lesson, you'll install Git on your macOS computer and create a GitHub account. These tools will help you track changes in your code and share your projects with others.

Why This Matters

Git and GitHub are essential tools for modern software development. Think of Git as a time machine for your code - it lets you:

  • Save snapshots of your work at different points in time
  • Undo mistakes by going back to earlier versions
  • Try new ideas without breaking your working code
  • Collaborate with other developers

GitHub is like a social network for code - it's where you store your projects online and work with others.

Part 1: Installing Git

What is Git?

Git is a version control system - software that tracks changes to your files over time. It runs on your computer and works entirely offline (though you can sync with online services like GitHub).

Check if Git is Already Installed

Git might already be on your Mac. Let's check:

  1. Open the Terminal app (Applications → Utilities → Terminal)
  2. Type this command and press Enter:
git --version

If you see something like git version 2.39.0, Git is already installed! You can skip to Part 2.

If you see "command not found", continue with the installation steps below.

Installation Steps

Option 1: Install via Xcode Command Line Tools (Recommended)

  1. In Terminal, type:
xcode-select --install
  1. A popup window will appear asking you to install the command line developer tools
  2. Click Install and agree to the license
  3. Wait for the installation to complete (it may take several minutes)
  4. Verify installation by typing:
git --version

Option 2: Install via Homebrew

If you have Homebrew installed (a package manager for macOS), you can use:

brew install git

Part 2: Configuring Git

Before using Git, you need to tell it who you are. This information will be attached to your commits (snapshots of your work).

Set Your Name and Email

In Terminal, run these commands (replace with your actual name and email):

git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"

Why this matters: Every change you save with Git will include this information, so others (and future you) know who made the change.

Verify Your Configuration

Check that your settings were saved:

git config --global user.name
git config --global user.email

You should see your name and email printed in the terminal.

Part 3: Creating a GitHub Account

What is GitHub?

GitHub is a website that hosts Git repositories (projects) online. It's like Google Drive or Dropbox, but specifically designed for code. GitHub adds social features like:

  • Storing your code in the cloud
  • Sharing projects with others
  • Contributing to open-source projects
  • Showcasing your work (like a portfolio)

Sign Up Steps

  1. Go to https://github.com
  2. Click Sign up
  3. Enter your email address
  4. Create a password (make it strong!)
  5. Choose a username (this will be public - like @yourname)
  6. Verify you're a human (complete the puzzle)
  7. Click Create account
  8. Check your email and verify your account

Tips for Choosing a Username

  • Use something professional - you might share this with employers
  • Keep it simple and easy to remember
  • Common patterns: firstname-lastname, firstnamelastname, or a variation

Part 4: Connecting Git to GitHub

To push code from your computer to GitHub, you need to authenticate (prove you own the account). We'll use SSH keys - a secure way to connect.

Step 1: Check for Existing SSH Keys

ls -al ~/.ssh

If you see files named id_rsa.pub or id_ed25519.pub, you already have SSH keys. Skip to Step 3.

Step 2: Generate a New SSH Key

Run this command (replace with your GitHub email):

ssh-keygen -t ed25519 -C "your.email@example.com"

When prompted:

  • Press Enter to save to the default location
  • Enter a passphrase (optional but recommended - like a password for your key)
  • Confirm the passphrase

Step 3: Add SSH Key to the SSH Agent

eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519

Step 4: Copy Your Public Key

pbcopy < ~/.ssh/id_ed25519.pub

This copies your public key to the clipboard.

Step 5: Add Key to GitHub

  1. Go to GitHub.com and log in
  2. Click your profile picture (top right) → Settings
  3. In the sidebar, click SSH and GPG keys
  4. Click New SSH key
  5. Give it a title (like "My MacBook")
  6. Paste your key (Cmd+V) into the "Key" field
  7. Click Add SSH key

Step 6: Test the Connection

ssh -T git@github.com

You should see a message like: "Hi username! You've successfully authenticated..."

Summary

What You've Accomplished

Tool What It Does Status
Git Tracks changes to your code locally ✅ Installed & Configured
GitHub Account Stores your code online ✅ Created
SSH Key Securely connects your computer to GitHub ✅ Generated & Added

What's Next?

In the next lesson, you'll learn what version control is and why developers use it. You'll understand the problems Git solves and how it works conceptually before diving into commands.

Troubleshooting

If Git installation fails:

  • Make sure your macOS is up to date
  • Try restarting your computer and running the command again
  • Check that you have enough disk space

If SSH key generation fails:

  • Make sure you're using the correct email (the one registered with GitHub)
  • Try using the older RSA algorithm: ssh-keygen -t rsa -b 4096 -C "your.email@example.com"

If SSH test fails:

  • Make sure you copied the entire public key (including the email at the end)
  • Check that you pasted it correctly in GitHub
  • Try removing and re-adding the key