How Can I Add an Empty Folder to a Repository?
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