Does git ignore empty folders?

GitVersion Control

Git Problem Overview


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?

Git Solutions


Solution 1 - Git

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.

Solution 2 - Git

Yes, git ignores empty folders.

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

Solution 3 - Git

Git tracks content not files.

A solution is proposed here.

Solution 4 - Git

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.

Solution 5 - Git

Yes, git ignores empty folders, some suggestions on how to solve that are:

  1. put a README file inside the folder and describe the folder content or why is the folder empty and must be kept
  2. put an empty file called .gitignore inside the folder
  3. (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

Solution 6 - Git

Yes, git will not track empty folders. Find a full discussion here on StackOverflow

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionEnoView Question on Stackoverflow
Solution 1 - GitJörg W MittagView Answer on Stackoverflow
Solution 2 - GitMichael ForrestView Answer on Stackoverflow
Solution 3 - GitpmrView Answer on Stackoverflow
Solution 4 - GitDustinView Answer on Stackoverflow
Solution 5 - GitAdemir Mazer Jr - NunoView Answer on Stackoverflow
Solution 6 - GitlabratmattView Answer on Stackoverflow