How Can I Add an Empty Folder to a Repository?
Short answer
Git tracks file content, not directories — an empty folder has no files for Git to hash, so it will never appear in a commit or be created on clone. The standard workaround is to place a small placeholder file inside the folder, conventionally named .gitkeep or .keep, with no content. Create it with touch path/to/folder/.gitkeep, stage it with git add path/to/folder/.gitkeep, and commit — collaborators will then receive the folder when they clone or pull. Some projects use a .gitignore inside the empty folder (with a rule to ignore everything except itself) to both preserve the folder and prevent future contents from being accidentally committed. If the folder is generated at runtime by a build process, it is usually better to document its creation in the README or build script rather than committing a placeholder file.
Short answer: Git does not track empty directories, but the standard workaround is to place a placeholder file (.gitkeep or .keep) inside the folder.
Let's start with a tiny bit of background information: Git does not care about folders - it cares about files. Therefore, if a folder is empty, Git will not offer you to add it to version control.
While there is no "standard" solution to this problem, there are a couple of different approaches to "circumvent" this behavior.
Adding a .gitkeep or .keep File
A popular solution is to add a file named .gitkeep (or .keep) to the folder. You can then stage and commit this file and, as a consequence, also add the folder to version control.
.gitkeep has become the more widely adopted convention because the .git prefix signals intent to other developers. Neither name has any special meaning to Git itself — any filename works.
Here are the commands to do this in a terminal:
mkdir logs/
touch logs/.gitkeep
git add logs/.gitkeep
git commit -m "Add logs directory"
git push origin main
Alternative: .gitignore as a Placeholder
Some teams use an empty .gitignore file instead of .gitkeep — this works identically and also gives you a ready-made place to add ignore rules for that directory later.
Learn More
- Check out the chapter Starting with an Unversioned Project – Command Line edition in our free online book