Git add all folder and all contents in folders

Goodmorning, I would like to add in my repository all folders and all files in folders. When I run command git add . all folders are added as files. How solve this problem?
Thank you really much
best regards

Git does not track folders as such, just files in folders. When checking out files folders will be created automatically as needed. If you want to create an empty folder the common procedure is to add a hidden file in that directory (e.g. .gitkeep, but any name works).

That said, creating any required directories that do not contain sources should usually be done by the build, not git.


Hi @denissanga, and welcome on board!

In which specific way the result of using git add . is being problematic? how is it affecting you and what were you expecting that did not happen?

As @airtower-luna mentioned:

In practical terms this means that folders are created as required by Git (on checkout). Since Git handles all file paths relatively to the repository root, stored filenames includes the sub-paths too (which is what you’re seeing in Git status reports, and other commands’ messages mentioning files).

In other words, folders are implicit in filenames — e.g. the img/house.gif file includes info about its parent folder. This is also the reason why empty folders are not being considered by Git.