Best .gitignore Practices for SDETs — for Test Automation Projects

Share with friends
⏱️ 𝑹𝒆𝒂𝒅𝒊𝒏𝒈 𝑻𝒊𝒎𝒆: 3 𝘮𝘪𝘯𝘶𝘵𝘦𝘴 ⚡️
Save Story for Later (0)
Please login to bookmark Close

“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 TypeExampleWhat it Does
Ignore file.envIgnores .env file
Ignore folderlogs/Ignores entire logs folder
Wildcard ignore*.logIgnores all .log files
Negate rule!important.logTracks 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)

Article Contributors

  • Aanchal Gupta
    (Author)
    Senior Specialist Testing @ Sunlife Global Solutions

    Experienced ETL Test Specialist @ Sunlife Global Solutions with a decade of proven expertise, dedicated to ensuring data integrity, quality, and seamless integrations. Throughout my journey, I have championed meticulous QA processes, ensuring adherence while spearheading cross-functional teams through successful project execution. My passion for precision and project management expertise has consistently led to on-time deliveries and resource optimization.

  • Ishan Dev Shukl
    (Reviewer)
    SDET Manager, Nykaa

    With 13+ years in SDET leadership, I drive quality and innovation through Test Strategies and Automation. I lead Testing Center of Excellence, ensuring high-quality products across Frontend, Backend, and App Testing. "Quality is in the details" defines my approach—creating seamless, impactful user experiences. I embrace challenges, learn from failure, and take risks to drive success.

Subscribe to QABash Weekly 💥

Dominate – Stay Ahead of 99% Testers!

Leave a Reply

Scroll to Top