What is Version Control?
Imagine writing a novel. You'd want to:
- Save different versions as you write
- Go back to earlier versions if needed
- Maybe collaborate with other authors
- See what changes were made and when
Version control is like having a time machine for your code! Git is the most popular version control system, and GitHub is like a social network for code.
Git vs GitHub
Think of it this way:
- Git: Like Microsoft Word - software on your computer for tracking changes
- GitHub: Like Google Docs - online platform for sharing and collaboration
Installing Git
Step 1: Check if Git is Already Installed
Open your terminal (Command Prompt on Windows, Terminal on Mac/Linux) and type:
git --version
If you see a version number, Git is already installed!
Step 2: Installation by Operating System
Windows Installation
- Download Git from git-scm.com
- Run the installer
- Important settings during installation:
- Select Components: Keep all defaults
- Default editor: Choose "Use Visual Studio Code as Git's default editor"
- PATH environment: Select "Git from the command line and also from 3rd-party software"
- Line ending conversions: Choose "Checkout Windows-style, commit Unix-style line endings"
- Terminal emulator: Select "Use Windows' default console window"
- Click through remaining options (defaults are fine)
- Verify installation: Open new Command Prompt and type:
git --version
Mac Installation
Option 1: Xcode Command Line Tools (Recommended)
- Open Terminal
- Type:
git --version - If not installed, you'll be prompted to install Xcode Command Line Tools
- Click "Install" and agree to the license
Option 2: Homebrew
- Install Homebrew if not already installed:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" - Install Git:
brew install git - Verify installation:
git --version
Linux Installation
Ubuntu/Debian:
sudo apt update
sudo apt install git
Fedora:
sudo dnf install git
Arch Linux:
sudo pacman -S git
Verify installation: git --version
Configuring Git
Now let's set up your Git identity. This is like creating your signature that will appear on all your code contributions.
Essential Configuration
# Set your name
git config --global user.name "Your Name"
# Set your email (use the same email for GitHub)
git config --global user.email "your.email@example.com"
# Set default branch name to 'main'
git config --global init.defaultBranch main
# Set VS Code as default editor
git config --global core.editor "code --wait"
# Enable color output
git config --global color.ui auto
Verify Your Configuration
# View all settings
git config --list
# View specific setting
git config user.name
Creating a GitHub Account
- Visit github.com
- Click "Sign up"
- Enter your details:
- Use the same email as your Git configuration
- Choose a professional username (employers will see this)
- Use a strong password
- Complete the verification process
- Choose the free plan
- Customize your profile (add a photo, bio, location)
Connecting Git to GitHub
We'll use SSH keys for secure authentication. Think of SSH keys like a special pair of keys: one private (kept on your computer) and one public (shared with GitHub).
Step 1: Check for Existing SSH Keys
# Check if you already have SSH keys
ls -al ~/.ssh
Look for files named id_rsa.pub or id_ed25519.pub
Step 2: Generate New SSH Key
# Generate a new SSH key (use your GitHub email)
ssh-keygen -t ed25519 -C "your.email@example.com"
# If you're using a legacy system that doesn't support Ed25519:
ssh-keygen -t rsa -b 4096 -C "your.email@example.com"
When prompted:
- Press Enter to accept default file location
- Enter a passphrase (optional but recommended)
Step 3: Add SSH Key to SSH Agent
# Start the ssh-agent
eval "$(ssh-agent -s)"
# Add your SSH key
ssh-add ~/.ssh/id_ed25519
Step 4: Add SSH Key to GitHub
- Copy your public key:
# Copy to clipboard (Mac) pbcopy < ~/.ssh/id_ed25519.pub # Copy to clipboard (Linux) xclip -sel clip < ~/.ssh/id_ed25519.pub # Or just display it to copy manually cat ~/.ssh/id_ed25519.pub - Go to GitHub → Settings → SSH and GPG keys
- Click "New SSH key"
- Give it a title (e.g., "My Laptop")
- Paste your key
- Click "Add SSH key"
Step 5: Test Your Connection
ssh -T git@github.com
You should see: "Hi username! You've successfully authenticated..."
Your First Repository
Let's create your first repository! A repository (or "repo") is like a project folder that Git tracks.
Create a Repository on GitHub
- Click the "+" icon in top right → "New repository"
- Name it "my-first-repo"
- Add a description: "Learning Git and GitHub"
- Check "Add a README file"
- Choose "MIT License"
- Click "Create repository"
Clone Repository to Your Computer
# Navigate to where you want to store your projects
cd ~/Documents
# Clone your repository
git clone git@github.com:YOUR_USERNAME/my-first-repo.git
# Enter the repository
cd my-first-repo
Make Your First Commit
# Create a new file
echo "# Hello Git!" > hello.md
# Check status
git status
# Add file to staging area
git add hello.md
# Commit with message
git commit -m "Add hello.md file"
# Push to GitHub
git push origin main
Essential Git Commands
Basic Workflow Commands
| Command | What it does | When to use it |
|---|---|---|
git status |
Check current state | Frequently! Always check before committing |
git add . |
Stage all changes | When you want to commit all modified files |
git add filename |
Stage specific file | When you want to commit only certain files |
git commit -m "message" |
Save changes locally | After staging files, describe what changed |
git push |
Upload to GitHub | Share your commits with others |
git pull |
Download changes | Get latest updates from team members |
The Git Workflow
Best Practices
Commit Messages
Good commit messages are like good code comments. They explain the "why", not just the "what".
- ✅ Good: "Fix navigation menu dropdown on mobile devices"
- ❌ Bad: "Fixed stuff"
- ✅ Good: "Add user authentication with JWT tokens"
- ❌ Bad: "Update files"
Commit Frequency
Commit early, commit often! Think of commits as save points in a video game.
- Commit after completing a small feature
- Commit before trying something experimental
- Commit when your code is working
- Never commit broken code
.gitignore File
Create a .gitignore file to tell Git which files to ignore:
# Node modules
node_modules/
# Environment variables
.env
# OS generated files
.DS_Store
Thumbs.db
# IDE files
.vscode/
.idea/
# Build outputs
dist/
build/
Troubleshooting Common Issues
Authentication Errors
If you get "Permission denied (publickey)":
- Check if SSH key is added to ssh-agent
- Verify SSH key is added to GitHub
- Test SSH connection:
ssh -T git@github.com
Merge Conflicts
When the same file is changed by multiple people:
- Git will mark conflicts in files
- Manually resolve conflicts
- Commit the resolved files
Forgot to Pull Before Pushing
# Get the latest changes first
git pull origin main
# If there are conflicts, resolve them
# Then push your changes
git push origin main
Assignment: Git and GitHub Setup
- Install Git on your computer
- Configure Git with your name and email
- Create a GitHub account
- Generate SSH keys and add to GitHub
- Create a new repository called "fullstack-course"
- Clone the repository to your computer
- Create these files:
- README.md with "# My Full Stack Journey"
- notes/day1.md with today's learnings
- .gitignore with common exclusions
- Commit and push your changes
- Add a screenshot of your repository on GitHub to the README
Bonus: Create a personal profile README on GitHub!
Next Steps
Congratulations! You now have a professional development environment set up. You're ready to start your coding journey!
Tomorrow, we'll dive into HTML fundamentals and start building web pages. Make sure your environment is working properly and all your accounts are set up.