Q: What is a `.gitkeep` file, and why do you sometimes see empty files with that name committed to repos?
Git does not track empty directories. If you create logs/ with nothing in it and run git add logs/, nothing happens — Git has nothing to ...
🛠️ Production Runbook & Step-by-Step Resolution
Initial Diagnostics & Root Cause Analysis
Git does not track empty directories. If you create logs/ with nothing in it and run git add logs/, nothing happens — Git has nothing to track because the directory has no files.
- Ensuring a
tmp/,logs/, oruploads/directory exists when someone clones the repo (the app expects the directory to exist at runtime). - Skeleton project templates where the directory structure matters.
Remediation & Permanent Safeguards
.gitkeep is a convention (not a Git feature) — it's an empty file placed inside an otherwise-empty directory so Git will track the directory. The name .gitkeep is arbitrary; you could use .placeholder or any filename. .gitkeep is just the community convention. Common use cases: If the directory should exist but its *contents* should be ignored (e.g., logs/ should be present but log files shouldn't be committed), combine both: This ignores everything inside logs/ except the .gitkeep file, preserving the directory.
# .gitignore
logs/*
!logs/.gitkeep
- Ensuring a tmp/, logs/, or uploads/ directory exists when someone clones the repo (the app expect...
- Skeleton project templates where the directory structure matters.