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 :-
[xml]# Ignore everything in this directory
*
# Except this file
!.gitignore[/xml]
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.
Thoughts?
I personally think the .gitignore option is better if you want the directory to always stay empty as far as git is concerned. If you just want the folder to exist (say for a template or a project base), then either would work.
Agreed James, I tend to use .gitignore as well most of the times.
Meaning of Statistics: The science of producing unreliable facts from reliable figures.
Blessed is he who may have found his work; let him ask few other blessedness.