By the end of this lesson, you will:
Version control is a system that records changes to files over time so that you can recall specific versions later. It allows you to:
Imagine you're writing code for a project:
Version control solves all these problems!
One. The Knight Capital Group Disaster (2012)
2. Pixar's Toy Story 2 Near-Disaster (1998)
3. Linux Kernel Development
:bulb: :bulb: Pro Tip In professional development, version control isn't optional-it's mandatory. Companies like Google, Microsoft, and Facebook commit code changes thousands of times per day. Without version control, this would be chaos.
Type | Storage | Collaboration | Backup | Speed | Examples |
---|---|---|---|---|---|
Local VCS | Local disk only | None | No redundancy | Fast (local) | RCS |
Centralized VCS | Central server | Good | Single point of failure | Slow (network) | SVN, Perforce |
Distributed VCS | Full copies everywhere | Excellent | Every clone is a backup | Fast (local ops) | Git, Mercurial |
Professional Context: Rarely used in modern development except for personal projects or configuration files.
Professional Context: Still used in some enterprises, especially for large binary files (game assets, CAD files).
Professional Context: Industry standard for software development. Git dominates with 90%+ market share.
Git is the most popular distributed version control system, created by Linus Torvalds in 2005.
GitHub is a web-based hosting service for Git repositories. It provides:
Git | GitHub |
---|---|
Version control system | Hosting service for Git repositories |
Command-line tool | Web-based graphical interface |
Installed locally on computer | Hosted on the cloud |
Manages source code history | Manages Git repositories |
brew install git
# Ubuntu/Debian
sudo apt-get update
sudo apt-get install git
# Fedora
sudo dnf install git
After installing Git, configure your identity:
# Set your name
git config --global user.name "Your Name"
# Set your email
git config --global user.email "your.email@example.com"
# Check your settings
git config --list
The basic Git workflow consists of:
Working Directory → Staging Area → Repository
(edit) (git add) (git commit)
:bulb: :bulb: Pro Tip: Best Practices for Version Control
- Commit Often: Make small, logical commits rather than large, monolithic ones
- Write Clear Commit Messages: Use the imperative mood ("Add feature" not "Added feature")
- Branch Strategically: Use feature branches for new development
- Review Before Committing: Always review your changes with
git diff
before committing- Never Commit Secrets: Use
.gitignore
for sensitive files
Issue: "fatal: not a git repository"
Solution: Initialize Git in your project directory with git init
Prevention: Always check if you're in the right directory with pwd
Issue: "Your branch is ahead of 'origin/main' by X commits"
Solution: Push your local commits with git push origin main
Prevention: Push regularly to keep remote in sync
Issue: "Merge conflict" Solution: Manually edit conflicted files, then add and commit Prevention: Pull latest changes before starting new work
Issue: "Permission denied (publickey)" Solution: Set up SSH keys or use HTTPS for authentication Prevention: Configure authentication before first push
Version control is an essential tool for modern software development. Git, combined with GitHub, provides a powerful platform for:
In the next lesson, we'll dive deeper into Git commands and start using version control in practice!
Challenge: Experience the difference between different VCS approaches
Part One: Simulate Local Version Control
Part 2: Use Git for the Same Task
# Initialize Git
git init
# Create a file
echo "Version 1" > project.txt
git add project.txt
git commit -m "Initial version"
# Make changes
echo "Version 2" > project.txt
git add project.txt
git commit -m "Update to version 2"
# View history
git log --oneline
# See differences
git diff HEAD~1
Reflection Questions:
Now that you understand what version control is and why it's critical for professional development, you're ready to start mastering Git commands and workflows. In the next lesson, we'll dive deep into essential Git commands and practice using them in real-world scenarios!