Ignoring Files
How to tell Git to completely ignore specific files and folders in your project.
The .gitignore file
Not every file in your project folder should be saved to Git. Some files are generated automatically, some are too large, and some contain secret passwords.
A .gitignore is a simple text file you place in the root of your project. Inside, you write a list of file names or folder names that you want Git to pretend don't exist.
Why it matters
If you commit a file containing API keys or passwords, they are permanently in your history and will be exposed when you push to GitHub.
If you commit the node_modules folder (which contains thousands of third-party library files), your repository will become massive, slow, and impossible for other developers to use.
How it works
Git reads the .gitignore file line by line. You can use exact file names (like .env), folder names (like node_modules/), or wildcards (like *.log to ignore all log files).
Crucially, a .gitignore file only works on untracked files. If you already committed a file, adding it to .gitignore later will not remove it from Git's memory.
Apply ignore rules to untracked files
Compare the files shown before and after these ignore rules. Already tracked files remain tracked.
# .gitignore .env node_modules/ *.log
Already tracked
Untracked files
node_modules/Ignored by matching rule
.envIgnored by matching rule
debug.logIgnored by matching rule
These rules hide matching untracked files from ordinary status output. An already tracked file is still tracked. Local simulation.
Check yourself
Pick an answer to lock it in, then read why. Getting one wrong is part of how it sticks.
Remember this
- Use
.gitignorefor secrets (.env) and generated code (node_modules). - Wildcards like
*.logare supported. - It only works on files Git isn't already tracking.
Done with this concept?
Mark it complete to track your progress. No login needed.