.gitkeep sense and usage
Today I first discovered a .gitkeep file in one of our new shop gits. I didn’t know anything about .gitkeep sense and usage so I had to research for it. This is what I found out and why it is not really useful, but often used.
.gitkeep sense and usage
In a new Git project I found an empty folder. It only contained one hidden file, which was called .gitkeep. Interesting I thought, I had never heard about such a file. The only Git file I was aware of was called .gitignore. With such a file you can list file and folders that are ignored by Git. Magento 2 has a .gitignore included which look like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | /.buildpath /.cache /.metadata /.project /.settings atlassian* /nbproject /sitemap /sitemap.xml /.idea /.gitattributes /app/config_sandbox /app/etc/config.php /app/etc/env.php /app/code/Magento/TestModule* /lib/internal/flex/uploader/.actionScriptProperties /lib/internal/flex/uploader/.flexProperties /lib/internal/flex/uploader/.project /lib/internal/flex/uploader/.settings /lib/internal/flex/varien/.actionScriptProperties /lib/internal/flex/varien/.flexLibProperties /lib/internal/flex/varien/.project /lib/internal/flex/varien/.settings /node_modules /.grunt /pub/media/*.* !/pub/media/.htaccess /pub/media/catalog/* !/pub/media/catalog/.htaccess /pub/media/customer/* !/pub/media/customer/.htaccess /pub/media/downloadable/* !/pub/media/downloadable/.htaccess /pub/media/import/* !/pub/media/import/.htaccess /pub/media/theme/* /pub/media/theme_customization/* !/pub/media/theme_customization/.htaccess /pub/media/wysiwyg/* !/pub/media/wysiwyg/.htaccess /pub/media/tmp/* !/pub/media/tmp/.htaccess /pub/media/captcha/* /pub/static/* !/pub/static/.htaccess /var/* !/var/.htaccess /vendor/* !/vendor/.htaccess |
All this files are by default excluded if you decide to put you project into a Git repository.
The problem
If you ever created a Git project you may know the problem, that you can not add an empty folder. Git only tracks files and file changes. Folders are only to structure your source files. During development you may create a module skeleton (for example a Magento 2 module structure) which you want to git and to use as a base for your module development.
You can initially put a hidden (.filename) file into each directory. With this, the folder will be usable if you clone this Git repository.
Conclusion
.gitkeep is an often used file. You may think that it is a standard or an official Git file. That is not true. If you want to add empty folders into you Git project you need to add an hidden file to it. You can name it .gitkeep, but there is no need to do this. You can name it somehow. .gitkeep is a not documented naming convention that is often used.