Include empty directories in Git repo

less than 1 minute read

Including an empty directory in a Git repo can be useful for binary or object directories, so you don’t have to bother with mkdir commands in the build system. Include an empty directory in a Git repo by creating an empty file, even if the directory itself is in .gitignore as follows. This example assumes bin/ contents should be ignored by Git, but the empty directory bin/ should exist in the Git repo.

  1. add to .gitignore:
  2. make an empty file in bin/ and add it to Git:
    touch bin/.ignore
    git add -f bin/.ignore
  3. git commit as usual.



Leave a comment