Git & GitHub
/Beginner
.gitignore
Definition
A text file that tells Git which files or folders to ignore in a project. Ignored files will not be tracked, staged, or pushed to GitHub.
Explain Like I'm New
There are some files that should NEVER be put on the internet. Passwords, massive 5GB database dumps, and the dreaded `node_modules` folder. You write the names of these files in the `.gitignore` file, and Git pretends they don't exist.
Real World Example
You start a Node.js project. The very first thing you do is create a `.gitignore` file and write `node_modules/` in it, preventing 50,000 files from being uploaded to your GitHub.
Common Use Cases
- •Security
- •Keeping repositories small and fast
Terminal Output
bash / terminal
/*
Example .gitignore file for a Node.js project:
*/
# Ignore the massive dependencies folder
node_modules/
# Ignore secret environment variables (Crucial for security!)
.env
.env.local
# Ignore all system-generated log files
*.log
# Ignore macOS junk files
.DS_Store
# Ignore the production build output folder
/dist
Interview Questions
basic
- If you put a file in `.gitignore`, but you ALREADY committed it yesterday, will Git ignore it??
intermediate
- What does `*.log` do in a `.gitignore` file?