Basics: from file to commit · Lesson 4 of 15
.gitignore and useful commit messages
Exclude generated and sensitive files, and write understandable history.
Not every file belongs in history: dependencies are generated, builds can be recreated, and secrets are forbidden. .gitignore holds patterns for untracked files: *.log for logs and dist/ for a directory.
git init -q -b main echo "*.log" > .gitignore echo "secret" > debug.log echo "code" > app.js git status -s
| Track | Ignore |
|---|---|
src/, package.json, README | node_modules/, dist/ |
.env.example | .env, private keys |
Shared config | logs, temp files |
A commit subject should complete “If applied, this commit will …”, so Add password reset validation beats changes. Use an imperative subject; an optional body explains why.
What's the output?
git init -q -b main echo "*.tmp" > .gitignore echo "draft" > notes.tmp echo "ship" > release.txt git status -s
What will this code print?
Exercise
Ignore .log, create app.js and debug.log, then show status; only .gitignore and app.js should appear.
?? .gitignore ?? app.js
git init -q -b main echo "code" > app.js echo "details" > debug.log git status -s
Learn more from
Played 0 of 2 games
Sign in to save your progress and earn XP.