Lesson01
beginnerIgnore Files with .gitignore
Goal
Keep generated files and secrets out of version control by listing them in .gitignore.
Not everything in a project folder belongs in its history. Installed packages can be reinstalled, logs are noise, and API keys must never be committed at all.
A .gitignore file lists the paths Git should pretend it cannot see. This repository has collected a log file, a secrets file and a node_modules folder: teach Git to ignore all three.
Objectives
0/4- Create a
.gitignorefile in the project root. (Current objective) - Commit
.gitignore, so the rules belong to the project. (Not started) .envis not tracked by Git. (Not started)git statusis clean: the log, the secrets andnode_modulesare all ignored. (Not started)
Your task nowStep 1 of 4
Create a .gitignore file in the project root.
Need help?
Reference
One pattern per line
.gitignore is a plain text file in the project root. Each line is a pattern:
debug.logignores exactly that file*.logignores every file ending in.lognode_modules/ignores a whole folder, trailing slash and allbuild/*.cssignores CSS files inbuild, but nothing deeper!keep.logmakes an exception to an earlier pattern
Blank lines are skipped and lines starting with # are comments.
Before and after
$ git status
On branch main Untracked files: (use "git add <file>..." to include in what will be committed) .env debug.log node_modules/
Once those three paths are listed in .gitignore, the same command reports nothing to commit, working tree clean. Git has not deleted anything: the files are still on disk, it has simply stopped offering them.
Three states a file can be in
Tracked
- Git has it in a commit
- Changes show up as
modified
Untracked
- Git can see it but has never recorded it
- Listed by
git statusevery time
Ignored
- Matched by a pattern in
.gitignore - Never listed, never staged by
git add .
Preparing your workspace…
Repository Graph
Click a commit to inspect it
Working Tree
Not a Git repository yet
No unstaged changes
Your working tree matches the staging area.
Staging Area
Files prepared for the next commit
No staged changes
Use git add to prepare files for your next commit.
Repository
Committed history
No commits yet
Use git commit to record staged changes.
