Skip to main content

📝 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.

graph LR A[Code Today] --> B[Git Tracks Changes] B --> C[Version 1] B --> D[Version 2] B --> F[Current Version] style A fill:#f9f,stroke:#333 style F fill:#9f9,stroke:#333

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

CommandPurpose
git initStarts a new repository
git addStages files
git commit -m "msg"Saves a snapshot with a message
git statusShows current project state
git logShows 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.