Lesson 2 of 8
The Core Loop: add & commit
Learn the everyday of editing, staging and committing. Once the staging area makes sense, most other commands are easier to follow.
echo "# My Project" > README.md
git status
# Untracked files: README.md (git sees it, isn't tracking it)
git add README.md # stage it
git status
# Changes to be committed: new file: README.md
git commit -m "Add README"
# [main (root-commit) a1b2c3d] Add README
git log --oneline # view history
# a1b2c3d Add READMEWhy the staging area? It lets you commit some changes but not others. Fixed a and also tweaked some styling? Stage and commit the bug fix by itself, then commit the styling separately. Small, focused commits make history readable and problems easy to trace.
git add file1.js file2.js # stage specific files
git add . # stage everything in current dir
git diff # what changed but is NOT staged
git diff --staged # what IS staged for next commit
git restore file1.js # discard unstaged edits (careful!)
git restore --staged file1.js # unstage, keep the edits# .gitignore — files git should never track:
# (create this file in the repo root)
node_modules/
*.log
.env
dist/
# Commit .gitignore itself so teammates share the rules.Finished reading?Mark it done to track your progress.
Tip: use the ← and → keys to move between lessons.