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
| Area | Location | Description |
|---|---|---|
| Working Directory | Local Computer | Your actual files on your hard drive. Where you make changes, write code, and delete files. |
| Staging Area (Index) | Local Computer | A rough draft space. Where you place files (using `git add`) that you want to include in your next commit. |
| Local Repository | Local Computer | The hidden `.git` folder. Where Git permanently saves your snapshots (commits) on your local hard drive. |
| Remote Repository | Cloud (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?