I created an Android project, added it to my git repo, comitted and pushed my clone to the master. Later I tried checking out the project and Eclipse complained about missing src folders. I checked my repo and the master repo and the src folders are missing (Im sure they were there when I created the project). So can someone explain what happened here? Im new to git so maybe I missed something?
-
possible duplicate of [git and empty folders](http://stackoverflow.com/questions/1767165/git-and-empty-folders) – Cascabel Jun 13 '10 at 03:23
6 Answers
Git doesn't ignore empty directories. It ignores all directories. In Git, directories exist only implicitly, through their contents. Empty directories have no contents, therefore they don't exist.
Or to put it another way: Git is a content tracker. Empty directories are not content.

- 254,901
- 44
- 429
- 631

- 363,080
- 75
- 446
- 653
-
35Not exactly. git has a concept of "tree" (which corresponds to a directory), and the tree actually has a sha1 hash, and thus has content: the list of blobs (files) and trees (sub-directories). So `git` actually can (in theory) record empty directories. The problem lies in the index file (the staging area): it only lists files; and commits are built from the index file. – hasen Jun 13 '10 at 08:05
-
And in unix land a directory like everything else is a type of file to further complicate the theory. – Craig.C Jul 07 '20 at 17:17
Yes, git ignores empty folders.
You can add an empty .gitignore
or .gitkeep
file to any folders you want included.

- 3,461
- 4
- 22
- 35
-
4Here is how to do it in one go... `find . -depth -not -path "*target*" -not -path "./.git/*" -type d -empty -print` [... plenty of stuff here ...] `find . -depth -not -path "*target*" -not -path "./.git/*" -type d -empty -exec touch {}/.gitignore \;` – Alain Pannetier May 06 '16 at 12:11
-
Yes, git ignores empty folders, some suggestions on how to solve that are:
- put a README file inside the folder and describe the folder content or why is the folder empty and must be kept
- put an empty file called .gitignore inside the folder
- (wich I like most) put an empty file called .gitkeep inside. This solution is contextual since if some one see the file will understand why is it in the folder

- 890
- 18
- 30
git ignores all directories whether they're empty or not.
git will recreate directories when building out a tree on disk when a file needs to exist in a directory that does not. Otherwise, no attention is paid to directories.

- 89,080
- 21
- 111
- 133
Yes, git will not track empty folders. Find a full discussion here on StackOverflow

- 1
- 1

- 1,821
- 2
- 20
- 21