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
Option 1: Using Homebrew (Recommended)
If you have Homebrew installed:
brew install git
Option 2: Download Installer
If you don't have Homebrew:
-
Visit Git's website
-
Download
- Click the first download link
- Open the downloaded
.dmgfile - Follow the installation wizard
-
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
-
Visit Git's website
-
Download
- Download will start automatically
- Open the downloaded
.exefile
-
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"
- Important settings during installation:
-
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
Set Default Branch Name (Optional but Recommended)
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
- Close terminal completely
- Open a new terminal window
- Try
git --versionagain
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
| Term | Meaning |
|---|---|
| Repository (repo) | Project folder that Git tracks |
| Clone | Download a repository from GitHub |
| Commit | Save a snapshot of changes |
| Push | Upload commits to GitHub |
| Pull | Download changes from GitHub |
| Branch | Parallel version of code |
| Merge | Combine 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.
External Resources
Want to learn more about Git?
-
Git Documentation: https://git-scm.com/doc
- When to use: Reference for Git commands
-
GitHub's Git Handbook: https://guides.github.com/introduction/git-handbook/
- When to use: Quick intro to Git concepts (15 min read)
-
Try Git (Interactive Tutorial): https://try.github.io
- When to use: If you want hands-on Git practice before working on our code
-
Git Cheat Sheet: https://education.github.com/git-cheat-sheet-education.pdf
- When to use: Quick reference for common commands
For now, you don't need to study Git deeply. You'll learn as you use it!