How can I add an empty directory (that contains no files) to a Git repository?
As mentioned it's not possible to add empty directories, but here is a one liner that adds empty .gitignore files to all directories.
ruby -e 'require "fileutils" ; Dir.glob(["target_directory","target_directory/**"]).each { |f| FileUtils.touch(File.join(f, ".gitignore")) if File.directory?(f) }'
I have stuck this in a Rakefile for easy access.