🔀 Setting Up Git & GitHub
Imagine writing a novel where you could rewind to any earlier draft, see exactly what changed and when, and safely collaborate with other authors. That's version control — a time machine for your code. In this lesson you'll install Git, configure your identity, create a GitHub account, connect the two securely with SSH keys, and make your very first commit.
Week 1 · Day 1 (Monday: Course Introduction & Development Environment) · Lecture 3
🎯 Learning Objectives
By the end of this lesson, you will be able to:
- Explain what version control is and how Git differs from GitHub
- Install Git on your operating system and configure your name, email, and defaults
- Describe the Git workflow: working directory → staging → commit → push
- Generate an SSH key and connect it to your GitHub account securely
- Create a repository, clone it, and make your first commit and push
- Write clear commit messages and use a
.gitignorefile
Estimated Time: 60 minutes
Practice: Create a real GitHub repository and push your first commit to it.
In This Lesson
What Is Version Control?
A version control system records the history of your project — every change, who made it, and when — so you can move backward and forward through time. When you accidentally break something, you rewind. When you want to try a risky idea, you branch off safely. When you work with others, everyone's changes merge together without emailing zip files around.
Think about writing a novel. You'd want to save named drafts, jump back to an earlier one, see what changed between them, and maybe co-write with a partner. Git gives your code exactly those powers. It's the most widely used version control system in the world, and knowing it is non-negotiable for any developer.
your files right now] -->|git add| B[Staging Area
changes you've picked] B -->|git commit| C[Local Repository
saved snapshot] C -->|git push| D[Remote Repository
GitHub] D -->|git pull| C
That four-box flow is the entire mental model of Git. Everything else is detail. We'll come back to it throughout the course, but internalize the direction of the arrows now: you stage changes, commit them into history, then push them up to GitHub to share and back them up.
Git vs GitHub
Beginners mix these up constantly, so let's nail the difference right away.
| Git | GitHub | |
|---|---|---|
| What it is | Software on your computer | A website / cloud service |
| Job | Tracks changes to your files | Hosts your repos online & enables collaboration |
| Analogy | Microsoft Word tracking changes locally | Google Docs sharing & collaboration online |
| Needs internet? | No — works fully offline | Yes — it lives in the cloud |
💡 The one-line summary
Git is the tool that versions your code; GitHub is a place to store and share Git repositories online. You can use Git with no GitHub at all — but pushing to GitHub backs up your work and becomes the portfolio employers will actually look at. (GitLab and Bitbucket are popular alternatives that work the same way.)
Installing Git
Step 1 — Check if it's already installed
Open a terminal (Command Prompt or PowerShell on Windows, Terminal on Mac/Linux) and run:
git --version
If you see something like git version 2.44.0, you already have it — skip to configuration. If not, install it below.
🪟 Windows
- Download the installer from git-scm.com
- Run it. The defaults are fine, but a few screens are worth setting deliberately:
- Default editor: choose "Use Visual Studio Code as Git's default editor"
- PATH: "Git from the command line and also from 3rd-party software"
- Line endings: "Checkout Windows-style, commit Unix-style line endings"
- Click through the rest and finish
- Open a new terminal and verify:
git --version
🍎 macOS
Easiest: just run git --version in Terminal. If Git isn't present, macOS offers to install the Xcode Command Line Tools — click Install and agree to the license.
Or with Homebrew:
# Install Homebrew first if you don't have it:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Then:
brew install git
git --version
🐧 Linux
# Ubuntu / Debian
sudo apt update && sudo apt install git
# Fedora
sudo dnf install git
# Arch
sudo pacman -S git
git --version
Configuring Git
Before your first commit, Git needs to know who you are — this identity gets stamped on every commit you make, like a signature. Run these once and they apply to every project on your machine (that's what --global means).
# Your name — appears on every commit
git config --global user.name "Your Name"
# Your email — use the SAME email you'll use for GitHub
git config --global user.email "your.email@example.com"
# Make new repos start on a branch called "main" (the modern default)
git config --global init.defaultBranch main
# Use VS Code for commit messages and merges; --wait pauses Git until you close the tab
git config --global core.editor "code --wait"
# Colorize Git's terminal output for readability
git config --global color.ui auto
Verify your setup
# See everything you've configured
git config --list
# Check a single value
git config user.name
⚠️ Use a consistent email
Set your Git user.email to the same address you register on GitHub. If they differ, your commits won't be linked to your GitHub profile — meaning your contribution history (the green squares employers love) won't fill in. Fixing it later is annoying; get it right now.
Creating a GitHub Account
GitHub will become your public coding home, so a little care up front pays off.
- Visit github.com and click Sign up
- Use the same email as your Git config
- Pick a professional username — employers will see it, so favor
jane-devoverxX_g4m3r_Xx - Choose a strong password and complete the verification
- Select the free plan — it's genuinely all you need
- Add a photo and short bio; a complete profile looks credible
📖 Why your username matters
Your GitHub URL becomes github.com/your-username — effectively a second résumé. Recruiters really do click it. Choose a name you'd be comfortable putting on a job application, because changing it later breaks links to your repositories.
Connecting With SSH Keys
To push code to GitHub without typing a password every time, you'll use SSH keys. An SSH key is a matched pair: a private key that stays secret on your computer, and a public key you hand to GitHub. GitHub uses the public key to verify requests signed by your private key — cryptographic proof it's really you, no password required.
Step 1 — Check for existing keys
ls -al ~/.ssh
Look for a file ending in .pub such as id_ed25519.pub. If one exists, you can reuse it and skip to Step 4.
Step 2 — Generate a new key
# Ed25519 is the modern, recommended algorithm — use your GitHub email
ssh-keygen -t ed25519 -C "your.email@example.com"
# Only if an old system lacks Ed25519 support:
ssh-keygen -t rsa -b 4096 -C "your.email@example.com"
When prompted:
- Press Enter to accept the default file location
- Optionally set a passphrase — recommended; it's an extra lock on your private key
Step 3 — Add the key to the ssh-agent
# Start the agent (the background helper that holds your key)
eval "$(ssh-agent -s)"
# Add your private key to it
ssh-add ~/.ssh/id_ed25519
Step 4 — Add the PUBLIC key to GitHub
- Copy your public key to the clipboard:
# macOS
pbcopy < ~/.ssh/id_ed25519.pub
# Linux (needs xclip)
xclip -selection clipboard < ~/.ssh/id_ed25519.pub
# Windows (Git Bash)
clip < ~/.ssh/id_ed25519.pub
# Or just print it and copy manually
cat ~/.ssh/id_ed25519.pub
- On GitHub: Settings → SSH and GPG keys → New SSH key
- Give it a descriptive title (e.g. "My Laptop")
- Paste the key and click Add SSH key
⚠️ Public vs private — never mix them up
Only ever share the .pub (public) file. The matching private file — id_ed25519, no extension — must never leave your computer or be pasted anywhere online. Treat it like the key to your house.
Step 5 — Test the connection
ssh -T git@github.com
Expected output
Hi your-username! You've successfully authenticated,
but GitHub does not provide shell access.
That message means success — the "no shell access" part is normal and expected.
Your First Repository
A repository (or "repo") is a project folder that Git tracks. Let's create one on GitHub, bring it to your computer, and push a change back.
on GitHub] --> B[Clone it
to your computer] B --> C[Edit / add files] --> D[git add + commit] D --> E[git push
back to GitHub]
Create it on GitHub
- Click the + in the top-right → New repository
- Name it
my-first-repo - Add a description: "Learning Git and GitHub"
- Check Add a README file
- Choose the MIT License
- Click Create repository
Clone it to your computer
# Go to where you keep projects
cd ~/Documents
# Clone using the SSH URL (the green Code button → SSH)
git clone git@github.com:YOUR_USERNAME/my-first-repo.git
# Move into the new folder
cd my-first-repo
Make your first commit
# Create a new file
echo "# Hello, Git!" > hello.md
# See what Git noticed
git status
# Stage the file (move it to the staging area)
git add hello.md
# Commit it into history with a clear message
git commit -m "Add hello.md with a greeting"
# Push the commit up to GitHub
git push origin main
Refresh your repo page on GitHub — hello.md is there. You just completed the full loop: edit → add → commit → push. That cycle is 90% of daily Git use.
Essential Git Commands
These are the everyday commands you'll use from day one. You don't need to memorize them cold — they'll stick through repetition.
| Command | What it does | When to use it |
|---|---|---|
git status | Shows what's changed and staged | Constantly — check before every commit |
git add . | Stages all changes | When you want to commit everything you changed |
git add <file> | Stages one specific file | When you want to commit only certain files |
git commit -m "msg" | Saves staged changes to history | After staging, with a message describing what changed |
git push | Uploads commits to GitHub | To back up and share your work |
git pull | Downloads others' changes | Before you start working, to get the latest |
git log --oneline | Lists past commits compactly | To review the project's history |
The .gitignore file
Some files should never be tracked — bulky dependencies, secret keys, OS clutter. A .gitignore file at your project root tells Git to ignore them:
# Dependencies — huge and re-installable, never commit these
node_modules/
# Secrets — API keys and passwords must stay out of Git
.env
# OS-generated junk
.DS_Store
Thumbs.db
# Editor folders
.vscode/
.idea/
# Build outputs
dist/
build/
⚠️ Never commit secrets
API keys, passwords, and .env files must go in .gitignore before your first commit. Once a secret is pushed to GitHub it's effectively public forever — even deleting it later doesn't remove it from history. When in doubt, keep it out.
Practice & Quiz
🏋️ Exercise: Ship your first repo
Goal: Go end to end — from installed Git to a commit visible on GitHub.
- Configure Git with your name and email (matching GitHub)
- Generate an SSH key and add the public half to GitHub
- Verify with
ssh -T git@github.com - Create a repo called
fullstack-courseand clone it - Add three files:
README.md("# My Full Stack Journey"),notes/day1.mdwith today's takeaways, and a.gitignore - Stage, commit with a clear message, and push
💡 Hint
To create the notes/ folder and file in one go: mkdir notes && echo "# Day 1 Notes" > notes/day1.md. Then git add . stages all three new files at once.
✅ Solution
git clone git@github.com:YOUR_USERNAME/fullstack-course.git
cd fullstack-course
echo "# My Full Stack Journey" > README.md
mkdir notes
echo "# Day 1 Notes: set up VS Code, Git, and GitHub." > notes/day1.md
printf "node_modules/\n.env\n.DS_Store\n" > .gitignore
git add .
git commit -m "Add README, day 1 notes, and gitignore"
git push origin main
Refresh GitHub — all three files should appear in your repository.
🎯 Quick Quiz
Question 1: Which command moves a changed file into the staging area?
Question 2: What's the difference between Git and GitHub?
Question 3: Which SSH key do you add to your GitHub account?
Best Practices & Troubleshooting
✅ Do — write good commit messages
A commit message should explain the why, not just the what. Compare:
- ✅ "Fix navigation dropdown not opening on mobile"
- ❌ "Fixed stuff"
- ✅ "Add user authentication with JWT tokens"
- ❌ "Update files"
✅ Do — commit early and often
- Commit after each small, working piece of a feature
- Commit before trying something experimental (an easy point to return to)
- Never commit broken code you know doesn't work
❌ Don't
- Don't commit
node_modules/,.env, or secrets — that's what.gitignoreis for - Don't let days of work pile into one giant commit; small commits are easier to understand and undo
- Don't share or paste your private key anywhere, ever
⚠️ Common issues
- "Permission denied (publickey)": your SSH key isn't set up right. Confirm it's added to the ssh-agent (
ssh-add -l) and added to GitHub, then re-runssh -T git@github.com. - Merge conflicts: when the same lines change in two places, Git marks the conflict in the file. Edit it to keep what you want, remove the
<<<<markers, thengit addand commit. - Push rejected (remote is ahead): someone (or you, elsewhere) pushed first. Run
git pull origin main, resolve any conflicts, then push again.
Summary
🎉 Key Takeaways
- Version control is a time machine for your code; Git is the tool, GitHub is the online home
- Configure Git once with your name and matching email so commits link to your profile
- The core loop is working directory →
add→commit→push - SSH keys authenticate you securely: share the public key, guard the private one
- Write clear commit messages and use
.gitignoreto keep junk and secrets out
📚 Additional Resources
- Official Git Documentation & the free Pro Git book
- GitHub Docs — Connecting to GitHub with SSH
- GitHub — Hello World quickstart
🚀 What's Next?
Your environment is fully set up: editor, version control, and a GitHub home for your work. Now the real building begins. The next lesson dives into HTML document structure — the skeleton every web page is built on.
🎉 Environment complete!
VS Code, Git, and GitHub are ready. You now have the exact toolkit professional developers use every day. Time to start building.