Master Git & GitHub From Scratch

Clear, practical, and structured lessons designed to take you from Git fundamentals to real-world GitHub collaboration.

Understanding the Three States

In Git, your local workflow revolves around three distinct states that control how your files are tracked and saved: the Working Directory, the Staging Area (Index), and the Local Repository.

Here is how the three states look and how files move between them:

1. The Working Directory (Modified State)

  • This is theactual folder on your computer where you create, delete, and edit your project files.

  • What happens here: When you modify a file, Git notices the change, but the file is considered modified.

2. The Staging Area / Index (Staged State)

The Staging Area is a hidden file or prep zone where Git prepares the changes for your next commit. Think of it as a loading dock where you gather packages before putting them on a delivery truck.

  • What happens here: ou choose exactly which modified files you want to include in your next save point. This allows you to group related changes together.

  • How to get here: You use the git add command to move files from the Working Directory to the Staging Area. The files are now staged.

3. The Git Directory / Repository (Committed State)

This is where Git permanently stores your project's metadata and object database (the hidden .git folder). When you use git commit, everything in your staging area is safely locked into the project's history.

  • State: Committed: The data is securely stored in your local database.

  • Analogy: The shipping box is taped, labeled, and securely stored in the warehouse.

The Workflow in Action

Step Command What it does State Change
Edit Modify code in your editor Changes files on your computer. Working Directory → Modified
Stage git add {filename} Prepares specific changes for a snapshot. Working Directory → Staging Area
Commit git commit -m "Message" Permanently saves the staged snapshot. Staging Area → Git Directory

The Workflow Lifecycle at a Glance

  • You modify a file in your Working Directory.
  • You stage the file (git add), which snapshots it in its current state.
  • You commit 1. the staged files (git commit), which permanently stores that snapshot into your Git directory.

Checking Your Current States

You can see which files are in which state at any time by running:

git status
  • Red text means files are in your Working Directory (Modified/Untracked).
  • Green text means files are in your Staging Area (Staged and ready to commit).