Track Empty Directories with git
There are times when you'd like to track an empty directory within git but there's a problem: git wont allow you to add a directory that doesn't have a file in it. The easy solution is putting an empty stub file within the directory, and the industry standard for that stub file name is .gitkeep
.
You can quickly create the file and commit the "empty" directory from command line:
touch my-empty-dir/.gitkeep
git add my-empty-dir/.gitkeep
git commit -m "Adding my empty directory"
The problem is simple, the solution is easy, but I wanted to highlight that .gitkeep
is the industry standard.
If you follow me on Twitter, you know that I've been working on a super top secret mobile application using Appcelerator Titanium. The experience has been great: using JavaScript to create easy to write, easy to test, native mobile apps has been fun. My...
CSS animations are right up there with sliced bread. CSS animations are efficient because they can be hardware accelerated, they require no JavaScript overhead, and they are composed of very little CSS code. Quite often we add CSS transforms to elements via CSS during...
We all love trusted JavaScript frameworks like MooTools, jQuery, and Dojo, but there's a big push toward using focused micro-frameworks for smaller purposes. Of course, there are positives and negatives to using them. Positives include smaller JS footprint (especially good for mobile) and less cruft, negatives...
It's no secret that Facebook has become a major traffic driver for all types of websites. Nowadays even large corporations steer consumers toward their Facebook pages instead of the corporate websites directly. And of course there are Facebook "Like" and "Recommend" widgets on every website. One...
If you want to keep empty directory in git and be sure that its eventually content won’t be pushed, you have to add line in
.gitignore
. Going to the point,.gitkeep
is one of the methods and the more common (from my experience) is to create.gitignore
withI’d be interested where the “
.gitkeep
is the industry standard” came from. Last time I was looking at a couple of repositories, the preference was an empty.gitignore
file.Good tips, Mathew and David!
@Mathew: When I use this tip, I usually include
*/
as well to exclude subfolders. This can be pretty handy for thoselog/
,cache
, andsessions
types of directories.