Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git and empty folders

So I see Git doesn't recognize folders, or should I say when the only change between commits is addition of empty folders to the working tree they're not show in git status after git add ..

How would you handle the need to add empty folders to the working tree (for runtime storage) and have them be reflected/created when other repositories pull from the current repository (one in which the folders were added)?

like image 688
deepblue Avatar asked Nov 19 '09 22:11

deepblue


People also ask

Does git track empty folders?

Since Git won't track empty directories, you have to trick it into doing so by adding a file in the directory to Git's index. Usually, people store a file called . gitkeep in a directory that they wish to track, but where the directory should stay empty for the time being.

Why git does not track empty folders?

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.

How do I commit a .git folder?

Enter git add --all at the command line prompt in your local project directory to add the files or changes to the repository. Enter git status to see the changes to be committed. Enter git commit -m '<commit_message>' at the command line to commit new files/changes to the local repository.


2 Answers

I usually put a .gitignore in those directories as you likely want to ignore any runtime generated data anyway.

like image 150
hallski Avatar answered Sep 22 '22 12:09

hallski


People often put an empty file as a placeholder in the folder to overcome that limitation...

like image 40
John Weldon Avatar answered Sep 24 '22 12:09

John Weldon