Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does git ignore empty folders?

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?

like image 272
Eno Avatar asked Jun 12 '10 21:06

Eno


People also ask

Does GitHub hide empty folders?

Git does not delete empty folder but it has no concept of folders therefore it does not track folders (git only tracks paths to your files, not folders, it treats file paths like how you'd treat URLs on a website).

Does Git store empty directories?

Git does not track empty directories.

Can you commit empty folders?

Yes, indeed, by design, you can not commit empty directories, containing no files, to a Git repository.

Can Gitignore ignore folders?

gitignore is a plain text file in which each line contains a pattern for files or directories to ignore. It uses globbing patterns to match filenames with wildcard characters. If you have files or directories containing a wildcard pattern, you can use a single backslash ( \ ) to escape the character.


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

like image 198
Jörg W Mittag Avatar answered Sep 20 '22 10:09

Jörg W Mittag


Yes, git ignores empty folders.

You can add an empty .gitignore or .gitkeep file to any folders you want included.

like image 39
Michael Forrest Avatar answered Sep 23 '22 10:09

Michael Forrest