By the end of this lesson, you will:
Definition: Version control is a time machine for your code. It tracks every change, lets you rewind mistakes, and enables collaboration without chaos.
macOS:
# Check if installed
git --version
# If not, install with:
brew install git
# Or download from git-scm.com
Windows:
# Download Git Bash from git-scm.com
# Includes Git and Unix-style terminal
Linux:
sudo apt-get install git # Ubuntu/Debian
sudo yum install git # Fedora
Set your identity (this appears in history):
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
# Verify configuration
git config --list
# Create project folder
mkdir my-awesome-project
cd my-awesome-project
# Initialize Git
git init
# Check status
git status
What Happens:
.git
foldermain
or master
# Copy a repository from GitHub
git clone https://github.com/username/repo-name.git
# Enter the folder
cd repo-name
Remember this pattern - you'll use it thousands of times:
Create or edit files normally
echo "# My Project" > README.md
Tell Git what to include
git add README.md
# Or add everything:
git add .
Save a snapshot with message
git commit -m "Add project README"
Share with the world
git push origin main
The most important command you'll ever use:
git status
What it tells you:
State | Meaning | What to Do |
---|---|---|
Untracked | New file Git doesn't know about | git add filename |
Modified | Changed but not staged | git add filename |
Staged | Ready to commit | git commit -m "message" |
Committed | Saved in history | git push to share |
# Add GitHub as remote
git remote add origin https://github.com/YOUR-USERNAME/YOUR-REPO.git
# Push your code
git push -u origin main
Deploy a website in 60 seconds:
<!DOCTYPE html>
<html>
<head>
<title>My Site</title>
</head>
<body>
<h1>Hello World!</h1>
<p>My first Git-deployed website!</p>
</body>
</html>
git add index.html
git commit -m "Add homepage"
git push origin main
Your site is live at: https://YOUR-USERNAME.github.io/YOUR-REPO/
These 6 commands cover 90% of daily Git use:
git status # What's happening?
git add . # Stage everything
git commit -m "msg" # Save snapshot
git push # Upload to GitHub
git pull # Download changes
git log --oneline # See history
Fix: Run git init
first
Fix: Make changes or create files first
Fix: Pull first: git pull origin main
Fix: Configure name and email (see setup)
Try this 5-minute exercise:
git-practice
favorite-food.txt
favorite-movie.txt
git log
to see your historyYou now know enough Git to:
These fundamentals will serve you throughout your entire career. Let's practice!