- [Cameron] Hey, I'm Cameron McKenzie.
You can follow me on Twitter @cameronmcnz if you want to.
For now, I just wanna talk to you about git init bare.
And no, not like Smokey the Bear,
that's a different spelling of bare.
I want to talk to you about a bare git repository.
Now, before I can really demonstrate
what a bare repository is,
the first thing I need to do is demonstrate
what a regular repository looks like.
So, I'm in my home directory,
I'm gonna create a new directory
called Fozzie, that's Fozzie bare.
And I'm gonna create a new git directory
with the git init command
now this git init command
is going to create a regular repository.
So this isn't a bare repository,
maybe I shouldn't have called it Fozzie
but you get the idea.
And in this repository, I can create files, I can add files,
I can do commits.
And all of the information about those commits
is stored in a subdirectory called .git.
And if I do ls -a to take a look at the hidden files,
you'll see that there's this .git directory.
And that .git directory holds all the information
about the commits about commit objects,
about the commit history, all of that stuff.
And in this current directory here,
I can do all of the different work that I need to do.
So I've got a directory right in the route
where I can put all of my files
and there's a sub-directory .git
with all the configuration
then I can do a git add and a git commit.
Okay. So that's a regular repository,
that's a regular git repository.
Now, what's the deal with a bare repository?
So the idea of the bare repository, is that,
the idea of the bare repository,
is that it doesn't have this working directory
where you can add code, write code, and do commits.
It only handles
the purpose of managing a history of commits,
allowing people to push to it and pull to it,
but you can't do development on it.
And so let me create a new directory here.
We'll have Smokey the Bear.
We'll move into Smokey,
and they'll do a git init command here.
Use the bare switch.
And now all of a sudden it'll initialize
a new directory.
But watch this, instead of having the working directory
where I can add code and do commits,
it's gonna have something a little different maybe ls -a,
notice branches config description,
that's all right in the root.
Whereas before the regular git directory,
if you do ls -a,
all of that stuff is under a subdirectory called .git.
I don't have that in the bare directory.
And if I do cd.git,
you'll notice that all of these things
that are in this particular directory here,
they're right in the root
or actually in the sub-directory .git.
And so the idea is with a regular git repository,
you've got all of the history
and the ability for people to push to it and pull from it.
But you've also got a working directory
a work tree where you can write your own code
and commit codes and do everything locally.
With a bare repository you don't have that
with the bare repository
it's simply there for people to push to
for people to pull from, it will maintain a history
but you can't do any actual work or development
in the root directory of it.
And so if you're setting up a server
that's when you create a bare directory
you can think of even GitHub, GitLab.
Those actually being bare directories
'cause no one's doing development in them
and it's just being used for push and pulls and fetches.
So there you go that's the key difference
between a regular git init and a git init bare.
Now I apologize if you wanted to learn about Smokey the Bear
and I kind of catfished you into this tutorial,
but if you did wanna learn about git init bare,
well, I hope you learned a thing or two,
if you wanna learn more about,
GitHub, GitLab, Enterprise Software Development
and Service side development.
Follow me on Twitter @cameronmcnz.
And I'm also the Editor in Chief over@theserverside.com.
And if you wanna learn more about Smokey the Bear,
I think that's the National Forestry Association in the US.
You can Google it.