📖 Chapter 3: Tracking Changes in Git

After creating a Git repository (either by cloning with git clone `repo-url` or initializing with git init), Git organizes your files into two categories:

Tracked files can exist in one of three states:

graph LR; A["Tracked Files"] --> B["📂 Unmodified (No Changes)"]; A --> C["✏️ Modified (Changes Made)"]; A --> D["📌 Staged (Ready to Commit)"]; style A fill:#ffcc00,stroke:#000,stroke-width:2px; style B fill:#99ff99,stroke:#000,stroke-width:2px; style C fill:#ff9966,stroke:#000,stroke-width:2px; style D fill:#66ccff,stroke:#000,stroke-width:2px;

📌 Understanding File States

Unmodified: The file is unchanged since the last commit.

Modified: The file has been changed but not yet staged.

Staged: The file is prepared for the next commit.

sequenceDiagram autonumber actor User as 👨‍💻 User participant WD as 📂 Working Directory participant SA as 📌 Staging Area participant LR as 📜 Local Repository User ->> WD: Creates a new file (❌ Untracked) WD ->> User: File is Untracked User ->> SA: Runs `git add` (📥 Staged) SA ->> User: File is now Tracked and Staged User ->> LR: Runs `git commit` (✅ Committed) LR ->> User: File is safely stored in the Repository User ->> WD: Modifies the file (📝 Modified) WD ->> User: File changes detected! User ->> SA: Runs `git add` again (📥 Staged Again) SA ->> User: Changes prepared for commit User ->> LR: Runs `git commit` again (🔄 Committed Again) LR ->> User: Changes permanently saved!

you can understand this way also :

graph LR; A[Untracked] -->|Add the file| B[Unmodified] B -->|Edit the file| C[Modified] C -->|Stage the file| D[Staged] D -->|Commit| B B -->|Remove the file| A %% Styling for a better appearance style A fill:#d3d3d3,stroke:#000,stroke-width:2px; style B fill:#008080,stroke:#000,stroke-width:2px; style C fill:#b8860b,stroke:#000,stroke-width:2px; style D fill:#b22222,stroke:#000,stroke-width:2px; linkStyle 0,1,2,3,4 stroke:#777,stroke-width:3px,color:#fff,font-weight:bold;

or

graph TD; %% 🎯 User Actions subgraph "🎯 User Actions" A["📄 Create/Edit File"]:::action B["➕ Add File"]:::action C["✏️ Modify File"]:::action end %% ⚡ Git States subgraph "⚡ Git States" X["🟥 Untracked"]:::state_untracked Y["🔵 Unmodified"]:::state_unmodified Z["🟠 Modified"]:::state_modified W["🟢 Staged"]:::state_staged end %% 🔀 Transitions A --> X B -->|"⚡ `git add`"| Y:::cmd C -->|"🟣 Edit"| Z:::cmd Z -->|"🔥 `git add`"| W:::cmd W -->|"✅ `git commit`"| Y:::cmd %% 🎨 Styling for Dark Mode classDef action fill:#FFC107,stroke:#FFF,stroke-width:2px,color:#000,font-size:14px,font-weight:bold; classDef state_untracked fill:#F44336,stroke:#FFF,stroke-width:2px,color:#FFF,font-size:14px,font-weight:bold; classDef state_unmodified fill:#2196F3,stroke:#FFF,stroke-width:2px,color:#FFF,font-size:14px,font-weight:bold; classDef state_modified fill:#FF9800,stroke:#FFF,stroke-width:2px,color:#FFF,font-size:14px,font-weight:bold; classDef state_staged fill:#4CAF50,stroke:#FFF,stroke-width:2px,color:#FFF,font-size:14px,font-weight:bold; classDef cmd fill:#333,stroke:#FFF,stroke-width:2px,color:#FFF,font-size:14px,font-weight:bold, font-family:monospace; linkStyle 0,1,2,3,4 stroke:#F44336,stroke-width:3px,color:#FFF,font-weight:bold;
Next Chapter: Checking File Status