I wonder if I can add an empty directory to my Git repository? If possible, how to do this?
I wonder if I can add an empty directory to my Git repository? If possible, how to do this?
According to the documentation it is not possible.
Can I add empty directories?
Currently the design of the Git index (staging area) only allows files to be listed, and nobody competent enough to make the change allow empty directories has cared enough about this situation to remedy it. Directories are added automatically when adding files inside them. That is, directories never have to be added to the repository, and are not tracked on their own. You can say "git add "and it will add the files in there. If you really need to you should create a file in it. .gitignore works well for this purpose (there is also a tool MarkEmptyDirs using the .NET framework which allows you to automate this task); you can leave it empty or fill in the names of files you do not expect to show up in the directory.
But you have this "hack" that allows you to achieve almost what you want. You create a file named .gitignore
with this content. This prevents new files from being created in the directory.
# Ignore everything in this directory
*
# Except this file
!.gitignore
A common way to do (more or less) this is to add a file in the folder. It is common to see repositories with folders that only have a blank file .gitkeep
inside.