This note describes the smallest useful Git workflow: initialize a repository, track a file, commit it, inspect history, and understand working-tree state.
mkdir demo-repo
cd demo-repo
git init
printf "first note\n" > notes.txt
git status
git add notes.txt
git commit -m "docs: add first note"The loop is:
- create or edit files
- inspect state with
git status - stage selected changes with
git add - record a snapshot with
git commit
git status
git status --shortUseful mental model:
- untracked files exist in the directory but are not yet part of Git history.
- modified files are tracked files with working-tree changes.
- staged files are selected for the next commit.
git log --oneline
git show --statUse git log --oneline for a compact history and git show --stat to see what changed in the latest commit.
Before staging:
git diffAfter staging:
git diff --cachedThis distinction matters because Git commits the staged snapshot, not every file currently changed in the working tree.
If Git asks for user identity:
git config --global user.name "Your Name"
git config --global user.email "you@example.com"Use repository-local configuration when you need a different identity for one repository:
git config user.name "Your Name"
git config user.email "you@example.com"Before every commit:
git status --short
git diff --cachedThis catches accidental files, missing files, and unrelated changes before they become part of history.