Git & GitHub Course
Git & GitHub
/
Beginner

Git Workflow Overview

Definition

The conceptual journey a file takes in Git: from the Working Directory, to the Staging Area, and finally into the Git Repository (.git directory).

Explain Like I'm New

1. You write code in your editor (Working Directory). 2. You pick exactly which files you want to save, and put them in a 'box' (Staging Area). 3. You tape the box shut, write a label on it, and put it in the storage room (Repository).

Real World Example

Packing for a trip. The Working Directory is your messy bedroom. The Staging Area is the suitcase open on your bed where you are placing clothes. The Commit is when you zip the suitcase shut.

Common Use Cases

  • •Understanding the mental model of Git

The Four Areas of Git

AreaLocationDescription
Working DirectoryLocal ComputerYour actual files on your hard drive. Where you make changes, write code, and delete files.
Staging Area (Index)Local ComputerA rough draft space. Where you place files (using `git add`) that you want to include in your next commit.
Local RepositoryLocal ComputerThe hidden `.git` folder. Where Git permanently saves your snapshots (commits) on your local hard drive.
Remote RepositoryCloud (e.g. GitHub)A version of your project hosted on the internet or network, used for backing up and sharing code with a team.

Terminal Output

bash / terminal
/* THE THREE TREES OF GIT: 1. Working Directory (You edit files here) ↓ `git add` ↓ 2. Staging Area (Index) (Files ready to be saved) ↓ `git commit` ↓ 3. .git Repository (Files permanently saved in history) */

Interview Questions

basic

  • What are the three main states that your files can reside in?

intermediate

  • Why does the Staging Area exist?

Flash Cards

Question

Three main states?

Click to reveal answer
Answer

Modified (Working Directory), Staged (Staging Area), and Committed (Repository).

Question

Why a Staging Area?

Click to reveal answer
Answer

It allows you to group related changes together. If you edited 10 files, but 5 are for a 'Login Bug' and 5 are for a 'Color Change', you don't want to save them all at once. The staging area lets you stage and commit just the 5 login files, and then do a separate commit for the color changes.