Skip to main content

The Core Git Workflow

To save snapshots of your files locally, Git uses a simple 3-stage loop: writing code, staging modified files, and committing.


1. The 3 Stages of Git​

Before saving anything, Git divides your directory files into three distinct zones:

[ Working Directory ] ───( git add )───> [ Staging Area ] ───( git commit )───> [ Local Repository ]
(Your edited files) (Packing the box) (Permanent snapshot)
  1. Working Directory: The physical folder on your computer where you write and edit code.
  2. Staging Area (git add): A digital preview table. You choose which specific files are ready to be included in the next snapshot.
  3. Local Repository (git commit): The secure internal database (inside .git) where snapshots are permanently stored.

2. Step-by-Step Command Flow​

Step 1: Initialize Git in your project folder​

git init

(Runs only once per project. It creates a hidden .git tracking database).


Step 2: Check current file status​

git status

(Shows which files are modified, untracked, or ready to be committed).


Step 3: Stage your modified files​

# Stage a specific file:
git add main.py

# Or stage ALL modified files in the folder (most common):
git add .

Step 4: Commit your snapshot with a descriptive message​

git commit -m "Add student marks calculator and error handling"

(The -m stands for message. Always write a short, clear description of what changed).


Step 5: View your commit history​

git log --oneline

(Displays a clean, single-line list of all previous save points with their unique commit hashes).


Quick Summary​

  • Three Architecture Zones: Working Directory (local modifications) -> Staging Area (git add) -> Git Repository History (git commit).
  • git init: Initializes a hidden .git folder in the project root.
  • git status: Shows tracked, modified, and untracked files in the current workspace.
  • git log --oneline: Displays chronological commit history with unique SHA hashes and descriptions.

What's Next?​

Let's look at how to protect API keys and skip redundant files using GitHub Repositories & .gitignore in the next lesson!