1. Computing

Can I add empty directories to Git repositories?

By

Question: Can I add empty directories to Git repositories?
Answer:

No. Git can only store files in its object store. There is currently no mechanism to store empty directories. When Git repositories are cloned, the directories are created on the fly as they are needed by files being unpacked by the object store.

A common solution to this problem is to place an empty file, such as a .gitignore file in the directory. So to add the directory empty/ to your Git repository, you could first create the .gitignore file with the touch command or a text editor, then run git add empty. It's not perfect, but it works.

$ ls -a empty
$ touch empty/.gitignore
$ git add empty
$ git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached ..." to unstage)
#
#  new file: empty/.gitignore
#
  1. About.com
  2. Computing
  3. Ruby
  4. Tutorials
  5. Using the Git Version Control Tool with Ruby
  6. Can Git Add Empty Directories?

©2014 About.com. All rights reserved.