- [Cameron] Hi, I'm Cameron McKenzie,
@cameronmcnz on Twitter,
and I wanted to talk to you about the .gitkeep file.
Now, here's the problem.
Git will not push empty directories
to a remote Git repository.
So, what people do is they put a fake file
in their empty files, called .gitkeep.
Git thinks there's something in there,
and so it will then push that empty directory
to the remote repository.
Now the only thing is, the directory's not empty,
because it's actually got a file in it, named .gitkeep.
But, it's kind of an unwritten convention, it tricks Git,
and everybody that's using Git
kinda understands what you're doing.
Now, I'm gonna show you a gitkeep example in just a second,
but I do want to point out,
.gitkeep is not part of the Git framework,
it's not part of the API, it's not part of the standard,
so .gitignore is, you know, you'll see the .git folder
is where all the configuration is for Git.
So all of those things are part of the Git tool.
.gitkeep, you know, it's kinda like the hidden menu
at In-N-Out Burger.
Everybody kinda knows about it,
but it's really not officially there.
So Git won't push empty folders up to GitHub,
or share them, for that matter, to any other directory,
and I could show you that simply by copying this Git URL
for the GitHub made easy project that I've got here
up on GitHub, I got a temp folder here,
and I'm gonna clone that repository,
so I'll do a little Git bash,
say, "Hey, Git, I want you to clone that repo,"
paste it in, and then you can see very quickly
this repo is cloned, there's the new file,
there's the README, the same as these right here.
And I can move into that directory,
do a little outlast,
and then you can see those files right there.
Now, watch what happens if I touch a hello.html file,
and then also make a new directory.
So I've touched that file,
so just created a basic hello.html file,
and I also created a new directory here,
I'm gonna do the git add,
and then I'm gonna do a git commit,
then I'm gonna do the old git push to origin.
And just allow me to put my username and password in here.
And now watch what happens.
Everything gets pushed up,
but some things don't get pushed up.
So if I do a refresh over here,
you can see hello was pushed, I created that file
just to prove that things were being pushed up.
But that new directory is not pushed up.
And the rule is, Git will not push empty directories.
So let me move into that folder,
new directory.
There's nothing in it, but I can do a little touch,
then you can just create this file anyway that you want,
and say "touch gitkeep."
And if I go into this folder here,
you'll notice there's a file named gitkeep.
This isn't a Git specific file.
This is kind of evolved from the community as a convention,
but there's nothing specific about this.
However, the rule with Git
is that any folder that has a resource in it
will get pushed to other Git repositories.
So if I now do a git commit,
or do a git add, gotta do the right commands,
then do a git commit,
and then do a git push to origin,
put in my password,
then all of a sudden, that folder will get pushed.
And so, I've got the new directory here,
I've got the gitkeep right there,
and if I come over to GitHub, do a quick refresh,
all of a sudden I've got the new directory,
and I've got the .keep in there.
And so there you go, that's how you can use gitkeep
to make sure that your new folders, empty folders,
get pushed to other Git, GitHub, or GitLab repos.
And there you go, that's how the gitkeep file works,
now if you enjoyed that tutorial,
why don't you head over to theserverside.com,
I'm the editor-in-chief over in there,
we've got lots of great Git, GitHub,
and tutorials on anything
that has to do with enterprise software development, really.
If you're interested in my personal antics,
you can follow me on Twitter @cameronmcnz,
and subscribe on YouTube.