What Is a .gitignore File? Hide the Junk in Git
You just ran npm install and a giant node_modules folder appeared. Maybe there’s a file with a secret password in it too. You really don’t want those getting uploaded to GitHub for everyone to see.
Good news: there’s a one-line fix.
A .gitignore file is a plain text list that tells Git which files and folders to skip, so things like node_modules and your secrets never get added to a commit or pushed to GitHub.
What is a .gitignore file?
Think of packing a bag for a trip. You pack only the essentials. Some things stay home. Your project works the same way.
The .gitignore file is your “do-not-pack” list for Git. You write the names of files and folders you want Git to leave alone, and Git pretends they aren’t there. They stay on your computer, but they never travel into your commits.
The name starts with a dot, which is why it’s said out loud as “dot gitignore.” That dot just means it’s a small config file that usually stays out of sight.
Why does this matter?
Two reasons, and both are big.
- Secrets stay private. If you accidentally push a file with a password or API key, anyone can read it. A
.gitignorestops that mistake before it happens. - Your repo stays small and clean. The
node_modulesfolder can hold thousands of files. There’s no reason to ship it. Anyone can rebuild it later by runningnpm install.
This is a real worry when you’re sharing code, especially for Indian developers pushing projects to GitHub for the first time. The rule is simple: never upload a secret by mistake, and never bloat your repo with files that don’t matter.
What does a .gitignore actually do?
It lists the things Git should ignore. When you run git add or git commit, Git checks this list and quietly skips anything on it.
So your project ends up with only your real code: the files you actually wrote. The bulky folder stays home. The private files stay home. Only what matters ships.
How do I create a .gitignore file?
You can make one with a single command. Open your terminal in your project folder and type:
echo node_modules >> .gitignore
Let’s read that line out:
echowrites one line of text.node_modulesis the folder we want to skip.>>sends that text into a file..gitignoreis the skip list itself.
Press enter, and the file is created. From now on, Git ignores node_modules forever in this project. Add a new line for each file or folder you want to hide, like a .env file that holds your secrets.
How do I check it worked?
Run git status. Before the .gitignore, Git would list node_modules as something waiting to be added. After, that giant folder simply disappears from the list. That’s your sign it’s working.
Key takeaways
- A
.gitignorefile is a list of files and folders Git should skip. - Use it to keep
node_modulesand secret files out of every commit. - Create one in a single line:
echo node_modules >> .gitignore. - This keeps your repo cleaner, safer, and smaller.
- Run
git statusto confirm the ignored files no longer show up.
You set up your project in the free Zero to AI Hero course, and now you’ve learned to keep the junk out of it. Next up, we put Node.js to work and build your very first web server.
🚀 Take the full free course: Zero to AI Hero — learn to build with AI from scratch. New lessons daily, in Hindi & English.
Want to actually learn this?
151 free 2-minute lessons — from "what's a file?" to building with AI.
▶ Start the free course