The difference between .gitignore and .gitkeep
Use .gitignore to exclude untracked paths and a placeholder such as .gitkeep to preserve an otherwise empty directory in a Git checkout.
.gitignore is a file Git reads to decide which untracked paths to ignore. .gitkeep is simply a conventional filename: Git gives it no special behavior. Committing a placeholder file lets a directory appear in a checkout even when it would otherwise be empty.
Use .gitignore to exclude generated or local files
node_modules/
*.log
.env
dist/
Ignore rules normally keep matching untracked files out of git status and ordinary git add operations. They do not stop Git tracking a file that is already in the index, and they do not erase content from earlier commits.
A .gitignore file applies to its own directory and descendants. Put repository-wide rules in the root file and more specific rules in subdirectories as needed.
Use a placeholder to preserve a directory
Git does not record empty directories as independent tracked entries. If the project expects a logs/ directory to exist after cloning, add a placeholder:
mkdir -p logs
touch logs/.gitkeep
git add logs/.gitkeep
To ignore runtime output while keeping that placeholder, add this to the root .gitignore:
logs/*
!logs/.gitkeep
Then stage the ignore file and commit both files:
git add .gitignore
git commit -m "Keep log directory without runtime output"
The rule excludes the contents of logs/, while the exception permits the placeholder. Do not replace it with logs/: excluding the directory itself prevents an exception inside it from working unless you also re-include the parent directory.
Choose a useful placeholder name
.keep or README.md works just as well as .gitkeep. A README can explain what creates the directory's contents and whether they should be committed. Update the exception pattern if you choose a different filename.
If the directory already contains a tracked file, a separate placeholder is unnecessary. An empty directory is not “ignored” by a hidden Git rule; there is simply no file entry for Git to record.
FAQ
Does .gitkeep need any content?
No. An empty file is sufficient. If you want an explanation, a README may be clearer.
Why does an empty directory not appear in a teammate's clone?
There was no tracked file beneath it. Add a placeholder and commit it; creating the directory locally is not enough.
Where should I put personal ignore patterns?
You can configure a personal excludes file:
git config --global core.excludesFile ~/.gitignore_global
Add machine-specific patterns such as .DS_Store there. Ignore entire IDE directories only when they do not contain team settings that the project intentionally tracks. Shared project rules belong in the repository's .gitignore.
See gitignore and Git configuration.
Contact us
Join the community
to join the community
Try Guance
Start online and pay only for what you use.
Get startedChoose a Guance plan