Chapter 02 • Lesson 2.9

Version Control with Git & GitHub Pages

Never lose code or name files index_final_v2_really_final.html again. Master the three trees of Git, write standard conventional commit messages, configure .gitignore, and publish your site to the world for free on GitHub Pages.

🎯 Learning Objectives

📖 Mental Model: The Time-Traveling Video Game Save Checkpoint

In an adventure RPG video game, before you enter a dangerous boss chamber, you save your progress at a glowing checkpoint stone. If your character falls into lava or makes a catastrophic mistake, you don't delete your entire console—you reload from your last save checkpoint.

Git is your time-traveling checkpoint system. Every commit is an immutable cryptographic snapshot of your entire project. If a new layout breaks or an experimental script crashes your site, you can instantly revert back to any exact second in your project's history without fear.

🎬 INTERACTIVE VISUAL PIPELINE 2.9 Version Control with Git
🌐
1. Input
Directives & Tags
⚙️
2. Parse
Tokenizer & AST
🌳
3. Layout
Box Model & Flow
🎨
4. Render
GPU Paint & Composite
PHASE 1: INPUT & DIRECTIVES
Browser receives declarative markup stream, parsing tag tokens and initializing component state.

The 3 States of Git Architecture

Files in a Git-tracked project move through three distinct stages before being shared:

┌──────────────────────┐ git add ┌──────────────────────┐ │ Working Directory ├────────────────────────────►│ Staging Area │ │ (Active file edits) │ │ (The index / cart) │ └──────────────────────┘◄────────────────────────────┤ │ git restore └──────────┬───────────┘ │ git commit ▼ ┌──────────────────────┐ git push ┌──────────────────────┐ │ Remote Repository │◄────────────────────────────┤ Local Repository │ │ (GitHub / GitLab) │ │ (Permanent history) │ └──────────────────────┘ └──────────────────────┘
Command What It Does Example
git init Initializes a new Git repository by creating a hidden .git/ directory. git init
git status Shows which files are modified, untracked, or staged for the next commit. git status
git add <files> Stages specific changes into the staging area (preparing the snapshot). git add index.html style.css (or git add .)
git commit -m "msg" Permanently seals the staged snapshot into the commit timeline with a message. git commit -m "feat: add contact form markup"
git log --oneline Displays a concise list of past commit hashes and messages. git log --oneline -n 5

Professional Conventional Commits

Senior software engineers use structured commit prefixes to make project histories readable and enable automated release changelogs:

The .gitignore File

Never commit OS junk files, private API keys, or heavy build artifacts to Git. Create a file named .gitignore in your project root:

# Operating System Artifacts
.DS_Store
Thumbs.db
desktop.ini

# Dependencies & Environment
node_modules/
.env
.env.local

# Editor Metadata (Keep settings, ignore personal cache)
.vscode/*
!.vscode/settings.json
*.log

Publishing for Free with GitHub Pages

Once your HTML project is pushed to a GitHub repository, you can publish it to a global CDN for free:

  1. Push your repository to GitHub (git push -u origin main).
  2. On GitHub, go to your repository Settings → Pages.
  3. Under Branch, select main (or master) and root folder / (root).
  4. Click Save. In ~60 seconds, your site is live at: https://yourusername.github.io/repository-name/!

Interactive Demo: Git Workflow Simulator

Experience how files transition through the Working Directory, Staging Area, and Committed History:

SYS: ACTIVE
HULL: 98%
CORE: STABLE
NET: ONLINE
HTML STARSHIP CODE TERMINAL git-simulator.html
LIVE RENDER & DIAGNOSTICS CORE TEMP: 45°C
INSPECTING DOM: VALID
TAGS: SCANNING...

🏋️ Hands-On Exercise: Author a Release Changelog Card

  1. Construct a clean HTML changelog card that displays recent Git commits formatted with Conventional Commit badges.
  2. Include 3 commits:
    • A feat: commit for adding navigation links.
    • A fix: commit for repairing a mobile layout contrast bug.
    • A docs: commit for adding deployment instructions to README.
  3. Use color-coded badges (e.g. green for feat, red for fix, blue for docs).
  4. Click ▶ Run Code to test your release timeline.
SYS: ACTIVE
HULL: 98%
CORE: STABLE
NET: ONLINE
HTML STARSHIP CODE TERMINAL exercise-2-9.html
LIVE RENDER & DIAGNOSTICS CORE TEMP: 45°C
INSPECTING DOM: VALID
TAGS: SCANNING...

⚠️ Common Pitfall: Forgetting to Stage Changes Before Committing

Running git commit -m "my message" without first running git add will produce "no changes added to commit". Git requires you to explicitly stage files so you have full control over exactly which changes are grouped into each atomic commit.

💡 Pro Tip: Inspect File Differences with git diff

Before you stage or commit code, run git diff in your terminal. Git will show you a color-coded line-by-line comparison of additions (green +) and removals (red -) so you never commit accidental debug code or rogue console logs!

📌 Key Takeaways

⭐ LEARN: HTML 🌟 ⚔️ QUIZ BATTLE ARENA // ACTIVE
3x
STREAK!
BONUS ACTIVE
COMBO
? Question 1 / 3

What is the role of the git add command in the Git workflow?

Question 1 / 3 Topic: HTML Fundamentals
14:28 REMAINING
XP REWARD
+250 XP
3x
STREAK!
BONUS ACTIVE
COMBO
? Question 2 / 3

What is the purpose of the .gitignore file?

Question 2 / 3 Topic: HTML Fundamentals
14:28 REMAINING
XP REWARD
+250 XP
3x
STREAK!
BONUS ACTIVE
COMBO
? Question 3 / 3

In Conventional Commits, what does the prefix feat: signify?

Question 3 / 3 Topic: HTML Fundamentals
14:28 REMAINING
XP REWARD
+250 XP