Installing Git

Git is a version control system that tracks changes to your code over time. It lets you save "snapshots" of your work, collaborate with others, and undo mistakes easily.

What You're Installing

Git - A version control system that:

  • Tracks every change you make to code
  • Lets you work on features without breaking the main code
  • Enables collaboration with other developers
  • Acts like "save points" in a video game

Why We Need This

The K12worX website code is stored in a Git repository on GitHub. You'll use Git to:

  • Download (clone) the code
  • Track your changes
  • Submit your contributions (pull requests)

Installation Steps

For Mac

If you have Homebrew installed:

brew install git

Option 2: Download Installer

If you don't have Homebrew:

  1. Visit Git's website

  2. Download

    • Click the first download link
    • Open the downloaded .dmg file
    • Follow the installation wizard
  3. Verify installation

    git --version
    # Should show: git version 2.x.x
    

Option 3: Xcode Command Line Tools

Git comes with Xcode Command Line Tools:

xcode-select --install

This opens a dialog - click "Install" and follow the prompts.

For Windows

  1. Visit Git's website

  2. Download

    • Download will start automatically
    • Open the downloaded .exe file
  3. Run the installer

    • Important settings during installation:
      • Default editor: Select "Visual Studio Code"
      • Adjusting PATH: Select "Git from the command line and also from 3rd-party software"
      • Line ending conversions: "Checkout Windows-style, commit Unix-style"
      • Terminal emulator: "Use MinTTY"
    • For everything else, keep the defaults
    • Click "Next" through remaining screens
    • Click "Install"
  4. Verify installation

    • Open Command Prompt or Git Bash
    git --version
    # Should show: git version 2.x.x
    

First-Time Git Configuration

After installing Git, you need to tell it who you are. This information will be attached to your commits (code changes).

Set Your Name

git config --global user.name "Your Name"

Replace "Your Name" with your actual name (keep the quotes).

Example:

git config --global user.name "Alex Johnson"

Set Your Email

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

Use the email you'll use for GitHub.

Example:

git config --global user.email "alex@example.com"

Verify Your Configuration

git config --global user.name
# Shows your name

git config --global user.email
# Shows your email

Modern Git uses "main" instead of "master":

git config --global init.defaultBranch main

Understanding Git Basics

Before we dive into using Git, let's understand what it does:

What is Version Control?

Imagine you're writing an essay:

  • Without Git: Save as essay.doc, essay-final.doc, essay-final-FINAL.doc, essay-final-ACTUALLY-FINAL.doc
  • With Git: One file, but Git remembers every version. You can go back to any previous version anytime.

Key Git Concepts

Repository (repo): A folder that Git is tracking

Commit: A snapshot of your code at a specific time

  • Like a save point in a game
  • Includes a message describing what changed

Branch: A separate line of development

  • Like a parallel universe where you can experiment
  • Changes on one branch don't affect other branches

Remote: A version of your repository stored on a server (like GitHub)

  • Lets you back up your code
  • Enables collaboration

Don't worry if this seems abstract. It'll make sense when you use it!

Testing Your Installation

Let's make sure Git works:

1. Check Version

git --version

Should show version 2.x.x or higher.

2. Check Configuration

git config --global --list

Should show your name and email.

3. Get Help

git --help

Shows Git documentation. Press q to quit.

Setting Up GitHub (Coming Soon)

Git is installed locally on your computer. To collaborate with others, you'll also need a GitHub account. We'll cover this in Section 02: Getting Started.

For now, just having Git installed is enough!

Common Issues

Command not found

Solution: Restart your terminal

  1. Close terminal completely
  2. Open a new terminal window
  3. Try git --version again

Permission denied (Mac/Linux)

Solution: Check if you need sudo

Some commands might need admin privileges. Try:

sudo git config --global user.name "Your Name"

Windows: Git Bash vs Command Prompt

Explanation: Git for Windows installs "Git Bash"

You can use either:

  • Command Prompt (cmd) - Windows' default terminal
  • Git Bash - Unix-like terminal (recommended for Git)

Git commands work in both, but Git Bash is more powerful.

Git Terminology Quick Reference

TermMeaning
Repository (repo)Project folder that Git tracks
CloneDownload a repository from GitHub
CommitSave a snapshot of changes
PushUpload commits to GitHub
PullDownload changes from GitHub
BranchParallel version of code
MergeCombine changes from branches

You'll learn these by doing! Don't try to memorize everything now.

What's Next?

Git is installed and configured! One more step before we start coding.

Next: Command Line Basics →


External Resources

Want to learn more about Git?

For now, you don't need to study Git deeply. You'll learn as you use it!