1. Technology
You can opt-out at any time. Please refer to our privacy policy for contact information.

Can I add empty directories to Git repositories?


Question: Can I add empty directories to Git repositories?

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. Technology
  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.