Repository Missing a Root .gitignore File
Checks whether a multi-file project contains a root .gitignore file to prevent accidental staging of .env secrets, local databases, dependencies, and build artifacts.
- Rule Slug
- missing-root-gitignore-file
- Affected Files
- .gitignore
- Detection Method
- Root File Presence
Vulnerable Pattern vs. Hardened Fix
# Project root without .gitignore
my-project/
├── src/
├── package.json
├── .env # Will be committed by 'git add .'!
└── node_modules/ # Thousands of files tracked!# .gitignore at project root
.env
.env.*
!.env.example
*.pem
*.key
*firebase-adminsdk*.json
*.sqlite
*.db
node_modules/
dist/
.DS_Store# Environment & Secrets
.env
.env.*
!.env.example
*.pem
*.key
*.p12
*firebase-adminsdk*.json
# Databases & Logs
*.sqlite
*.sqlite3
*.db
*.log
# Dependencies & Build Outputs
node_modules/
dist/
build/
.next/
.astro/
__pycache__/
.venv/
vendor/
# OS & Editor Artifacts
.DS_Store
Thumbs.dbWhy This Fails in Production
A well-crafted root .gitignore file is the first line of defense in every Git workflow. Without a root .gitignore in place, running git add . or staging changes in an IDE’s Source Control panel automatically tracks everything inside the working tree, including local .env files, temporary TLS private keys, SQLite development databases, OS metadata (.DS_Store), editor workspace configs, and gigabytes of node_modules/ or vendor/ dependencies.
Even if your repository happens to contain no sensitive files at the exact moment you initialize it, shipping without a root .gitignore creates a latent trap for every future contributor and CI script. The first teammate who adds a local .env.local file to test Stripe webhooks, or generates a debug SQL dump while reproducing a bug, will commit those artifacts straight into the shared repository because Git has no ignore rules protecting the workspace.
In addition to security leaks, missing .gitignore files cause severe operational friction: bloated Git repositories that take minutes to clone, unreadable pull requests polluted with thousands of generated files in dist/ or .next/, and cross-platform merge conflicts over .DS_Store or IDE cache files.
Initializing every repository on day one with a thorough root .gitignore covering both security-critical files (.env*, *.pem, *.key, service-account*.json, *.sqlite) and stack-specific build directories prevents accidental leaks before they can occur.
Remediation Steps
- 1Create a .gitignore file at the root of your repository using the one-click patch provided by PushCheck.
- 2Tailor the file to your tech stack (Node.js/TypeScript, Python, PHP/Laravel, Go, Rust, Docker) while always retaining secret and key-file exclusions.
- 3Run git status to verify that local .env files, dependencies, and build artifacts no longer appear under Untracked files.
- 4If unwanted files were already committed before adding .gitignore, untrack them cleanly with git rm -r --cached <path>.
Copy tested .gitignore setups for Node, PHP, Python, and Docker on BackendRecipes.
Frequently Asked Questions
- Does PushCheck trigger this rule when I paste a single snippet in Quick Config mode?
- No. The missing root .gitignore check runs only when auditing a multi-file local folder or GitHub repository so single-snippet quick checks stay focused and noise-free.
- What if I have a global ~/.gitignore_global on my laptop?
- A personal global gitignore protects only your own machine, not your teammates, contractors, or CI environments. Every repository should still commit a root .gitignore file.
- Should I ignore .env.example in .gitignore?
- No. Ignore .env and .env.* first, then explicitly re-include your sanitized template with !.env.example so new developers can copy it easily.