← Back to list

The GitHub Survival Guide: Stop Pushing Your Secrets & Bloat

We’ve all been there. You finish a feature, hit that big “Commit” button in VS Code, and boom your private API keys are live on GitHub for…

Tharindu Yehan · 2026-04-16 10:11 · 1 claps · 2.7 min read
#github #gitignore #secrets #env #github-push
Open on Medium ↗
Wiki topics: 🔓 · Open Source

The GitHub Survival Guide: Stop Pushing Your Secrets & Bloat

We’ve all been there. You finish a feature, hit that big “Commit” button in VS Code, and boom your private API keys are live on GitHub for the world to see, or you’ve just uploaded 400MB of node_modules.

Let’s fix that workflow and make sure you never leak a secret again.

1. What is .gitignore and Why Should You Care?

Think of Git as a very diligent biographer. By default, it wants to record every single change in your folder. But some things don’t belong in history:

  • Secrets (.env): Your database passwords and API keys.
  • Bloat (node_modules/): Massive folders that others can just install themselves.
  • Junk (.DS_Store, dist/): System-specific files or build artifacts.

A .gitignore file tells Git: "Hey, ignore these files. Don't track them, don't stage them, and definitely don't push them."

2. Never Push node_modules (Seriously!)

If there is one thing you should never push, it’s the node_modules folder.

  • It’s Huge: It can contain thousands of files. Pushing it makes your repo slow to download and takes up massive space on GitHub.
  • It’s Unnecessary: Everything inside is listed in your package.json. When someone else downloads your code, they just run npm install to get the exact same folders.
  • Compatibility: Some modules are built specifically for your computer’s operating system. Pushing them might actually break the code for someone on a different OS.

3. Push the Contents, Not the Container

A common mistake is pushing your “Project Folder” inside another folder.

  • Bad Structure: My-Git-Repo / My-App-Folder / package.json
  • Good Structure: My-Git-Repo / package.json

Why? Tools like Vercel, Netlify, or Heroku look at the root level (the very first folder) to find your settings. If your code is buried inside an extra folder, these services won’t know how to run your app. Keep your package.json and .gitignore at the very top!

4. “I added it to .gitignore but it’s STILL on GitHub!”

This is the #1 point of confusion. Git only ignores untracked files. If you pushed your .env file before you created the .gitignore, Git is already "tracking" it. Simply adding it to the ignore list now won't remove it from the repo.

The Fix: The “Forget This” Command

Tell Git to stop tracking the file without deleting it from your computer:

git rm --cached .env
  • **git rm --cached**: Removes the file from Git's memory but keeps it on your hard drive.

After you run this, commit and push. The file will vanish from GitHub.

5. Does the VS Code “Commit” Button Actually Work?

Yes. VS Code is just a visual layer for Git.

  1. When you save your .gitignore, VS Code usually turns ignored files grey.
  2. The Golden Rule: Look at the “Changes” list in the Source Control tab before clicking commit. If you see .env or node_modules there, stop. It means they are already being tracked, and you need to run the rm --cached command first.

6. How to Handle a Project Already on GitHub

If your project is already live and you just realized it’s a mess, follow this “Clean Sweep”:

  1. Update .gitignore: Add everything you want to hide.
  2. Clear the Cache:
git rm -r --cached . 
git add . 
git commit -m "Clean up ignored files and structure"

3. Push: git push origin main.

7. Pro-Tip: The .env.example Strategy

Since you aren’t pushing your .env file, how do others know what keys they need? Create a file called .env.example with the keys but not the values.

**.env.example (Push this!):**

DATABASE_URL=
STRIPE_API_KEY=

⚡ The Emergency Checklist

If you accidentally pushed a secret:

  1. Add to .gitignore.
  2. **git rm --cached <file>**.
  3. Commit and Push.
  4. Rotate your keys. (Crucial: Your secret is still in the Git history. Change your passwords/API keys immediately!)

Stay safe out there!

Feel free to leave your thoughts and questions in the comments below. If you found this article helpful, don’t forget to clap and share!

Connect with me: ***Portfolio | GitHub***


메타데이터
post_id
e62f58aca976
slug
the-github-survival-guide-stop-pushing-your-secrets-bloat-e62f58aca976
url
https://medium.com/@TYehan/the-github-survival-guide-stop-pushing-your-secrets-bloat-e62f58aca976
canonical_url
https://medium.com/@TYehan/the-github-survival-guide-stop-pushing-your-secrets-bloat-e62f58aca976
author_url
https://medium.com/@TYehan
status
ok
fetched_at
2026-06-11 05:11:55