QABash Community Forum

Please or Register to create posts and topics.

Best .gitignore Practices for SDETs β€” for Test Automation Projects

"Oops… Why Did I Just Commit My node_modules Folder? 😩"

We've all been there.

You push your code, feeling like a boss... until someone pings you on Slack:

"Hey, did you mean to upload 4,000 files in node_modules?"

Cue the facepalm.

That’s where .gitignore comes in β€” your project's silent bodyguard. In this post, I’ll show you exactly how to use .gitignore the right way, tailored to real-world setups like Java, Python, Selenium, Playwright, and Node.js.

Let’s save your repo from future embarrassment. πŸ’ͺ


πŸ€” What is .gitignore and Why Should You Care?

Imagine you’re packing for a trip. You want to bring clothes πŸ§₯, not trash πŸ—‘οΈ. But you accidentally pack your laundry, receipts, and last night’s pizza box.

Git works the same way. It tracks files for version control β€” but not everything needs to be tracked.

.gitignore is a list where you say:

β€œHey Git, don’t pack these files in the suitcase.”

No more clutter. No more embarrassing commits. Just clean code, every time.


🧰 How .gitignore Actually Works (In Simple Words)

Git looks at your .gitignore file before it adds files to the repo.
If the file matches a rule β€” it skips it.

It’s like telling Git:

β€œIgnore everything in logs/, skip all .env files, and don’t touch __pycache__/ ever again.”

You create a .gitignore file in your root directory and define what Git should avoid. Boom. Done.


πŸ” Anatomy of a .gitignore File

Here's how you write rules:

Rule Type Example What it Does
Ignore file .env Ignores .env file
Ignore folder logs/ Ignores entire logs folder
Wildcard ignore *.log Ignores all .log files
Negate rule !important.log Tracks important.log even if .log is ignored


πŸš€ Real-Life .gitignore Templates for Popular Tech Stacks

Let’s skip the theory and get practical. Here are plug-and-play examples for different stacks πŸ‘‡


🐍 Python Projects

__pycache__/
*.pyc
.env
venv/
*.log

βœ… Why?

  • __pycache__/ is auto-generated
  • .env may contain secrets
  • venv/ is local-only


🌐 Node.js + Playwright

node_modules/
dist/
.env
*.log
test-results/

βœ… Why?

  • node_modules/ is huge and rebuildable
  • .env and test-results/ contain runtime/local data


β˜• Java with Selenium

*.class
target/
*.log
.settings/
.project
.classpath

βœ… Why?

  • .class and target/ are built files
  • .project and .classpath are IDE configs (e.g., Eclipse)


🌍 General Web Projects

.DS_Store
.env
npm-debug.log*
coverage/

βœ… Why?

  • .DS_Store is Mac-only junk
  • coverage/ clutters with test data


πŸ’‘ Pro Tips to Git Ignore Like a Pro

βœ… Tip 1: Use GitHub’s .gitignore templates β€” they’ve got presets for nearly every language πŸ§™β€β™‚οΈ

βœ… Tip 2: Add .gitignore before you start committing. Git won’t ignore already-tracked files 🚫

βœ… Tip 3: Need to ignore something retroactively? Run:

git rm -r --cached foldername/

βœ… Tip 4: Keep .gitignore under version control too! That way your whole team stays in sync 🀝

βœ… Tip 5: Organize by context:

# Environment
.env

# Logs
*.log

# Dependencies
node_modules/


🚫 Common Mistakes to Avoid

❌ Adding .gitignore too late. Git will already track files unless you tell it otherwise β€” early birds win 🐦
❌ Using wildcards incorrectly. *.js β‰  **/*.js β€” one is top-level, the other is recursive
❌ Forgetting to check GitHub templates. There’s a ready-to-use one for everything from Android to Unreal Engine
❌ Ignoring .env in public repos. Yes, people do accidentally upload passwords 🀐


🌟 Expert Advice (And Aha! Moments)

πŸ” Aha! Git doesn’t ignore files already tracked. So even if you add node_modules/ to .gitignore, Git won’t drop it unless you untrack it manually.

πŸ’‘ Run this to fix it:

git rm -r --cached node_modules/

πŸ”„ Want to reapply your .gitignore rules? Use:

git rm -r --cached .
git add .

πŸ“š Bonus: Add your global ignores using:

git config --global core.excludesfile ~/.gitignore_global

Perfect for OS files like .DS_Store, Thumbs.db, etc.


🎯 Wrapping It Up: Clean Commits, Happy Team

.gitignore isn’t just a file β€” it’s peace of mind. It keeps your commits clean, your repo light, and your teammates happy. 🧼

Here’s your quick takeaway:

  • Add .gitignore early 🏁
  • Tailor it to your tech stack πŸ”§
  • Use templates to save time πŸ•’
  • Don't track local junk πŸ—‘οΈ
  • Share the same .gitignore across your team πŸ’¬


πŸš€ What’s Next?

πŸ‘‰ Read: Oops! I Committed My Secrets 😱 β€” Here’s How to Fix It in Git

πŸ‘‰ Explore: Top Git Commands Every Tester Should Know

πŸ‘‰ Learn: How to Undo Anything in Git (Beginner’s Survival Guide)

Scroll to Top
×