Making Git to Add Empty Directories

Since git is a “content” based SCM, and empty directories by git are not considered to be content [ which is arguable ], the only way to add them is to add “.gitignore” to every empty directory.

That may sound like a weird task after each time you create a Grails / Rails / Spring Roo / … project, since there are going to be many empty directories right from start.

To ease the pain, here is an alias you can add to your “.bashrc” to use before “git add .”:

# add '.gitignore' to all the empty dirs
alias ged='for i in $(find . -type d -regex ``./[^.].*'' -empty); do touch $i"/.gitignore"; done;'

one liner author: justinfrench.com