🌐 Phase 2 · Remote Collaboration 🟡 Intermediate MODULE 05

GitHub Essentials

⏱️ 45 min
💻 Hands-on
🧩 5 Quiz Questions
🏗️ 1 Challenge
Course progress62%
🎯 What you'll learn: What GitHub is and why it's the home of open source. How to create an account and your first repository. Connecting your local Git repo to GitHub using SSH or HTTPS. Setting up SSH keys for secure, password-free authentication. Pushing your first commit, cloning repos, and writing a standout README.

What is GitHub?

GitHub is a cloud-based hosting platform for Git repositories. While Git is the tool that tracks your code history on your computer, GitHub lets you store that history online — making it accessible from anywhere and shareable with anyone.

But GitHub is much more than just a backup. It's a social coding platform where millions of developers collaborate on projects, discover open-source code, showcase their work to employers, and contribute to software that powers the world.

🌍
Git ≠ GitHub
Git is the version control system — a CLI tool invented by Linus Torvalds. GitHub is a company that built a platform around Git. Alternatives to GitHub include GitLab, Bitbucket, and Gitea — they all work with Git, but GitHub is by far the most popular with over 100 million developers.

GitHub gives you: remote repository hosting (your code in the cloud), collaboration tools (pull requests, code review, issues), CI/CD pipelines (GitHub Actions), project management (Projects, Milestones), and your developer portfolio (your GitHub profile is your resume).

Creating a GitHub Account & Repository

Head to github.com and sign up for a free account. Choose your username carefully — it becomes part of your GitHub profile URL (github.com/yourusername) and will be seen by employers.

Creating Your First Repository

Once signed in, click the + icon in the top right → New repository. You'll need to configure a few options:

🔓 Public Repository
Anyone on the internet can view your code. Perfect for open source projects, portfolios, and learning. GitHub Pages hosting is free for public repos.
🔒 Private Repository
Only you and people you explicitly invite can see the code. Use for personal projects, client work, or anything you're not ready to share. Free on all GitHub plans.
💡
Initialize with a README?
If you're starting fresh on GitHub (no existing local repo), check "Add a README file". This creates the first commit for you. If you already have a local repo with commits, leave it unchecked — an initialized repo will cause conflicts when you try to push.

Connecting Local to Remote

After creating a GitHub repo, you need to link your local Git repository to it. The remote is given an alias — by convention it's called origin.

Connecting a local repo to GitHub
BASH
# Add the remote (replace with your actual repo URL)
git remote add origin git@github.com:username/my-repo.git

# Verify the remote was added
git remote -v
# Output:
# origin  git@github.com:username/my-repo.git (fetch)
# origin  git@github.com:username/my-repo.git (push)

# List all remotes
git remote

# Remove a remote (if you need to change it)
git remote remove origin

# Change a remote URL
git remote set-url origin git@github.com:username/new-repo.git

SSH vs HTTPS

There are two ways to connect to GitHub: SSH and HTTPS. HTTPS is simpler to set up initially but requires entering credentials. SSH uses cryptographic keys and is the professional standard — once set up, you never type a password again.

SSH URL
git@github.com:user/repo.git
Uses your SSH key. No password. Secure. Recommended.
HTTPS URL
https://github.com/user/repo.git
Uses personal access token. Fine for beginners.

SSH Key Setup

SSH keys work like a lock and key. You generate a key pair — a private key that stays on your machine and a public key that you share with GitHub. When you connect, GitHub verifies your private key matches the public key on file. You never send a password.

Generating and adding an SSH key
BASH
# Step 1: Generate a new SSH key (use your GitHub email)
ssh-keygen -t ed25519 -C "you@email.com"
# Press Enter to accept default location (~/.ssh/id_ed25519)
# Enter a passphrase (optional but recommended)

# Step 2: Start the SSH agent
eval "$(ssh-agent -s)"

# Step 3: Add your private key to the agent
ssh-add ~/.ssh/id_ed25519

# Step 4: Copy your PUBLIC key to clipboard
cat ~/.ssh/id_ed25519.pub
# (Copy the output — starts with ssh-ed25519...)

# Step 5: Test your connection to GitHub
ssh -T git@github.com
# Expected: Hi username! You've successfully authenticated...
🔑
Adding the key to GitHub
Go to GitHub → Settings → SSH and GPG keys → New SSH key. Paste your public key (the content of id_ed25519.pub), give it a title like "My Laptop", and click Add SSH key. Done — that machine can now authenticate without a password.

Your First Push

With your remote connected and SSH key set up, you're ready to push your local commits to GitHub. The first push uses -u to set up upstream tracking — after that, a simple git push is enough.

Push, pull, and the sync cycle
BASH
# First push: -u sets up tracking (do this once per branch)
git push -u origin main

# After that, just:
git push

# Pull remote changes to your local repo
git pull origin main
# Or just:
git pull

# Fetch without merging (inspect before applying)
git fetch origin
git diff main origin/main  # see what's different
git merge origin/main      # then apply
🔄
The push/pull cycle
The daily workflow: pull at the start of the day (get others' changes), work and commit locally, push at the end. This keeps everyone in sync. git fetch is like pull but safer — it downloads changes without applying them, so you can review first.

Cloning Repositories

git clone downloads a complete copy of a remote repository — including all commits, branches, and history — to your local machine. It's how you start working on any existing project.

Cloning a repository
BASH
# Clone into a new folder (folder name = repo name)
git clone git@github.com:username/my-repo.git

# Clone into a specific folder name
git clone git@github.com:username/my-repo.git my-project

# Clone via HTTPS
git clone https://github.com/username/my-repo.git

# What clone does automatically:
# 1. Creates a local folder
# 2. Initializes Git inside it
# 3. Adds 'origin' remote pointing to the source
# 4. Downloads all commits, branches, tags
# 5. Checks out the default branch (usually main)

Clone vs Fork

Clone creates a local copy of any repo on your machine. You can push back if you have write access. Fork creates your own GitHub copy of someone else's repo. Forks are used when you want to contribute to a project you don't own — you fork it, make changes in your copy, then send a Pull Request to the original. We'll cover forks in depth in Lesson 6.

GitHub README — Your Project's Front Door

The README.md file is the first thing people see when they visit your repository. A great README instantly communicates what the project does, how to install it, and how to use it. It's written in Markdown — a lightweight markup language.

A great README template
MARKDOWN
# Project Name

A one-line description of what this project does.

## ✨ Features
- Feature one
- Feature two
- Feature three

## 🚀 Quick Start
```bash
git clone https://github.com/username/project.git
cd project
npm install
npm start
```

## 📸 Screenshot
![App screenshot](./screenshot.png)

## 🛠️ Built With
- JavaScript
- Node.js
- GitHub Actions

## 📄 License
MIT © 2025 Your Name
🏅
Add badges to your README
Shields.io badges add visual status to your README: build passing, license type, version number, and more. Example: ![Build](https://img.shields.io/github/actions/workflow/status/user/repo/ci.yml). They make your project look professional and give visitors instant info at a glance.
🧩 Knowledge Check — Lesson 5
Test your GitHub Essentials knowledge. 5 questions.
1. What command connects your local repository to GitHub?
2. What does git clone do?
3. SSH keys are better than passwords for GitHub because:
4. What does the -u flag do in git push -u origin main?
5. What is the key difference between git clone and a fork?
🐙
GitHub Challenge — Lesson 5
Your first repo on GitHub · Intermediate
Challenge: Create, Clone, Commit & Push

1. Create a GitHub repository called my-first-repo (public, no README)
2. On your machine: mkdir my-first-repo && cd my-first-repo && git init
3. Connect it: git remote add origin git@github.com:YOURUSERNAME/my-first-repo.git
4. Create a README.md with your name and what you're learning
5. Stage & commit: git add . && git commit -m "docs: add initial README"
6. Push: git push -u origin main
7. Visit your GitHub repo URL and verify the README appears
💡 Show hints
  • Make sure SSH is set up first — run ssh -T git@github.com to test
  • If you get a "main vs master" error, run git branch -M main before pushing
  • Copy the exact SSH URL from the GitHub repo page (green Code button → SSH tab)
  • If you initialized with a README on GitHub, you may need to git pull --rebase origin main first
Finished this lesson?
Mark it complete to track your progress.
🎉

Lesson 5 Complete!

Your code is on GitHub! Now let's master the collaborative workflow with Pull Requests.

Lesson 05 of 09Git & GitHub Mastery