Include empty directories in Git repo

Including an empty directory in a Git repo is usually an anti-pattern, but can be done by creating an empty file. This can work even if the directory itself is in .gitignore. This example assumes build/ contents should be ignored by Git, but the empty directory should exist in the Git repo.

  1. add to .gitignore:

  2. make an empty file in build/ and add it to Git:

    touch build/.ignore
    git add -f build/.ignore
  3. git commit as usual.