A .gitkeep file is a convention-based placeholder file used to force Git to track an otherwise empty directory.
Git doesn't track empty directories - if you commit a folder with no files, it won't be included in your repository. The .gitkeep file solves this problem.
# Without .gitkeep - empty directory won't be tracked
mkdir logs
git add logs/ # This does nothing
git commit -m "Add logs directory" # Directory won't be committed
# With .gitkeep - directory will be tracked
mkdir logs
touch logs/.gitkeep
git add logs/.gitkeep
git commit -m "Add logs directory" # Now directory is tracked- Preserving directory structure: Ensuring required folders exist
- Placeholder for future files: Logs, uploads, cache directories
- Configuration directories: Where files will be added later
project/
├── src/
├── logs/
│ └── .gitkeep # Keeps logs directory in repo
├── uploads/
│ └── .gitkeep # Keeps uploads directory in repo
└── config/
└── .gitkeep # Keeps config directory in repo
- Not a Git feature: .gitkeep is just a naming convention
- Alternative to .gitignore: Some use .gitignore for similar purpose
- File content: Typically empty, but can contain documentation
- Can be named anything: The convention is .gitkeep, but any file works
The .gitkeep file is essentially a harmless "hack" to work with Git's limitation of not tracking empty directories.