Episode 3 of 12
How Git Works
Understand the Git workflow — working directory, staging area, and repository.
Before using Git commands, it's important to understand how Git works under the hood.
The Three States
Git has three main areas where your files can live:
- Working Directory — your project folder with actual files you can edit
- Staging Area (Index) — a prep area where you choose which changes to include in the next commit
- Repository (.git) — the database where Git stores all committed snapshots
The Git Workflow
Working Directory → Staging Area → Repository
(edit) (git add) (git commit)
- Modify files in your working directory
- Stage changes you want to include using
git add - Commit staged changes to the repository using
git commit
File States
- Untracked — new files Git doesn't know about
- Tracked — files Git is watching for changes
- Modified — tracked files that have been changed
- Staged — modified files marked for the next commit
- Committed — safely stored in the repository
Visualising the Flow
[Working Dir] → git add → [Staging] → git commit → [Repository]
↑ |
└──────────── git checkout ────────────────────────────────┘
The .git Folder
When you initialise a Git repository, a hidden .git folder is created. This contains all the version history. Never delete this folder or you'll lose all your history.