Keep Empty Folders in Git with .gitkeep File

Within a few months we migrated from SVN to Git in our company. During the migration, we recognized empty folders for Caching or meant to be for generated PDFs, were not added to the Repository. Git saves itselfs adding empty folders in the version control and does not persuade itself with commands like “git add foldername” or “git add *”.

Use .keep Files 

For the reason Git needs to have a file in a folder to add it to the repository, it has been adopted to developers to accomplish Git this desire. Just create an empty .gitkeep, .keep or .whatever file in the usually empty folder.
With a commit and push it’s done. Easy, isn’t it?

[quote]$ mkdir pdfs

$ touch pdfs/.keep[/quote]

.gitignore Adjustment

If there are Log – or like in our case generated PDF files – which shouldn’t be added in the git repo, it is recommended to add a few entries to the .gitignore file.

[quote]# ignore all generated PDF files

# don’t ignore keep files
!.gitkeep[/quote] I am in the habit of adding a short description text in the .gitkeep file to let others understand the meaning of the file. Doesn’t hurt anyone and in the best case the colleague is happy to have something learnt without Googling.

This post is also available in: deDeutsch (German)

Published by

Christopher Piontek

Ich bin ein technikbegeisterter Blogger, nebenberuflich (Fern-)Student der Wirtschaftsinformatik, hauptberuflicher Webentwickler und schreibe auf gerne Technik-News, Tutorials und Reviews. Meine favorisierten Themen sind #Software, #Internet und digitale Fotografie.

Leave a Reply

Your email address will not be published. Required fields are marked *