Skip to content

Instantly share code, notes, and snippets.

@gengwg
Created September 24, 2025 16:26
Show Gist options
  • Save gengwg/1ec03727082d0ad0c1d8e84b3a09eb19 to your computer and use it in GitHub Desktop.
Save gengwg/1ec03727082d0ad0c1d8e84b3a09eb19 to your computer and use it in GitHub Desktop.
what is .gitkeep file?

A .gitkeep file is a convention-based placeholder file used to force Git to track an otherwise empty directory.

Why it's needed

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.

How it works

# 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

Common use cases

  • Preserving directory structure: Ensuring required folders exist
  • Placeholder for future files: Logs, uploads, cache directories
  • Configuration directories: Where files will be added later

Example directory structure

project/
├── src/
├── logs/
│   └── .gitkeep      # Keeps logs directory in repo
├── uploads/
│   └── .gitkeep      # Keeps uploads directory in repo
└── config/
    └── .gitkeep      # Keeps config directory in repo

Important notes

  • 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment