📝 Lesson 1: Git Foundations
Your journey into version control starts here.
🎯 Learning Objectives
By the end of this lesson, you will be able to:
- Understand why version control is essential.
- Explain the three states of Git (Working, Staging, Repository).
- Initialize a repository and perform basic commits.
In This Lesson
What is Git?
Think of Git as a time machine for your code. At its core, the .git directory is the database that tracks every change you make to your project. It allows you to track changes, revert to previous versions, and manage complex projects without the fear of losing your hard work.
The Three States of Git
Git manages your files through three distinct states. Mastering this mental model is crucial for effective Git usage.
- Working Directory: Where you actively edit files.
- Staging Area: Where you prepare files for a commit.
- Repository: Where Git permanently stores your snapshots.
🔑 Key Insight: Staging
The staging area (index) is Git's secret weapon. It allows you to construct atomic commits—grouping related changes together—instead of just committing everything you touched.
Why It Matters
Collaboration is hard without proper tools. Git allows team members to work independently on different features, merging their changes into the main codebase effortlessly.
Distributed Version Control
Unlike centralized systems, Git is distributed. Everyone has a full copy of the project history, making it reliable, fast, and capable of working offline.
Git vs GitHub
Git is the tool installed on your computer. GitHub is the platform in the cloud where you host your Git repositories, share code, and collaborate.
Essential Toolkit
| Command | Purpose |
|---|---|
git init | Starts a new repository |
git add | Stages files |
git commit -m "msg" | Saves a snapshot with a message |
git status | Shows current project state |
git log | Shows commit history |
💡 Pro Tip: Git Status
Get into the habit of running git status frequently. It tells you exactly what Git sees: what's modified, what's staged, and what's untracked. It's the best way to avoid accidental commits.