Kit Ho Kit Ho - 1 year ago 90
Git Question

What is the difference between "git init" and "git init --bare"?

What is the different between

git init
git init --bare
? I found that a lot of blog post requires
for their Git server?

From the man page, it said:


Create a bare repository. If GIT_DIR environment is not set, it is set to the current working directory

But what does it actually mean? Is it required to have
for the Git server setup?

Answer Source

Non-Bare Git Repo

One creates a repository with a working directory so you can actually work (git clone). After creating it you will see that the directory contains a .git folder where the history and all the git plumbing goes. You work at the level where the .git folder is.

Bare Git Repo

The other creates a repository without a working directory (git clone --bare). You don't get a directory where you can work. Everything in the directory is now what was contained in the above case.

Why You Would Use One vs. the Other

The need for git repos without a working directory is the fact that you can push branches to it and it doesn't manage what someone is working on. You still can push to a repository that's not bare, but you will get rejected as you can potentially move a branch that someone is working on in that working directory.

So in a project with no working folder, you can only see the objects as git stores them. They are compressed and serialized and stored under the SHA1 (a hash) of their contents. In order to get an object in a bare repository, you need to git show and then specify the sha1 of the object you want to see. You won't see a structure like what your project looks like.

Bare repositories are usually central repositories where everyone moves their work to. There is no need to manipulate the actual work. It's a way to synchronize efforts between multiple people. You will not be able to directly see your project files.

You may not have the need for any bare repositories if you are the only one working on the project or you don't want/need a "logically central" repository. One would prefer git pull from a the other repositories in that case. This avoids the objections that git has when pushing to non-bare repositories.

Hope this helps

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download