Those familiar with Git, will know that Git only tracks files and not folders. What that means is, if a folder is empty (does not have any files in it), Git will totally ignore it, as there is nothing to track as far as Git is concerned. Now, sometimes, we do run into situations where we want to include a folder in the project directory tree, even if it’s empty. Consider a folder for storing user uploaded content, it could be empty to begin with. To make matters worse, this uploads folder could have different contents on different environments. I could be testing with test images on local setup and the production environment would have real uploads. You get the idea…there can be many more examples.
Anyways, what I’ve been doing is to add a .gitignore file to this empty folder with contents as follows :-
# Ignore everything in this directory * # Except this file !.gitignore
This will ensure that directory stays empty and will always be tracked in the Git repo.
There is one other way of tracking empty directories that I have seen some people follow, and that is to add a file called .gitkeep in their empty directories. Technically, since the directory is not empty anymore, Git will track it.
I am more in favour of option #1, the once that I am already doing.