📸 Git Basics — init, config, commits

Before branches or GitHub, there's one machine, one folder, and three simple stages. Master this and everything else is a variation on the theme.

1. The Story So Far

📖 Alex Mercer just joined TechLabs Inc. as a junior developer. His first task: build a Python task manager called taskmanager. He creates the folder, writes app.py, requirements.txt, and README.md — then his senior says: "Now make Git watch this folder forever."

$ mkdir taskmanager && cd taskmanager
$ git init
Initialized empty Git repository in /home/alex/taskmanager/.git/
🧠 Analogy: git init doesn't create your files — it plants a hidden brain (the .git folder) next to them that will remember every version of every file, forever, from this second onward.

2. What git init Actually Creates

The .git/ folder is Git's memory. Never delete it — that's your entire project history, gone.

📁 taskmanager/ app.py README.md requirements.txt .git/ ← Git's brain Inside .git/ — what each part does HEAD → which branch you're currently on config → repo-specific Git settings objects/ → every file's content & every commit refs/ → pointers to branches & tags hooks/ → scripts that auto-run on Git events

3. Tell Git Who You Are — git config

📖 Alex makes his first commit — Git shows "Unknown User." His senior: "You must configure Git before your first commit. Every commit carries your identity forever."
# Run ONCE per machine — applies to every repo
git config --global user.name  "Alex Mercer"
git config --global user.email "alex@techlabs.com"
git config --global init.defaultBranch main
Config levelScope & file
--systemAll users on the machine — /etc/gitconfig
--globalYour user account only — ~/.gitconfig
--local (default)This repository only — .git/config
Priority: local overrides global overrides system. Set a work email globally, then override it per-repo with git config user.email "..." (no --global) for a client's private repo.

4. Watch the Three-Stage Workflow — Step by Step

📖 "Think of Git like a camera," Alex's senior explains. "git add puts your files in the frame. git commit takes the photo. git status tells you what's currently in the frame."

Click Step to move app.py through all three stages:

📝 Working Directory your actual files on disk app.py (untracked) git add 📋 Staging Area (Index) the waiting room before commit app.py (staged) git commit 🗄 Repository (.git) permanent history — never changes a3f9b12 ✔
app.py is untracked — Git sees it but isn't watching it yet.
✉️ Analogy: Working directory = drafts. Staging area = selected drafts ready to send. Repository = sent items that can never be unsent.

5. The Daily Commands

# Always run this first — see what changed
git status

# Stage files
git add .              # all modified/new files (NOT deletions)
git add app.py          # one specific file
git add -A              # everything, including deletions

# Commit — the permanent snapshot
git commit -m "feat: add MongoDB database module and env template"
CommandStages
git add .All modified and new files in current directory
git add filenameOnly that specific file
git add src/Everything inside the src/ directory
git add -AEverything, including deletions (more thorough than .)
⚠️ Gotcha: git add . does NOT stage deleted files. If you deleted files and want Git to record it, use git add -A instead.

6. Commit Messages That Don't Embarrass You

Alex's actual commit history so far, each one a single logical change:

a3f9b12 initial commit: add app.py, README and requirements
4341109 feat: add MongoDB database module and env template
Habit to teach early: one commit = one logical change. "Fixed stuff" tells nobody anything six months from now; "feat: add MongoDB database module" does. Chapter 9 covers the full Conventional Commits format.
🔓 You're reading a free chapter of Git — the first two are open.
Unlock the rest of this course with a one-time payment.
Unlock this course →
🔓 See course prices