What is a bare Git repository?

A repository without a Working Tree. What does that mean?

Image

The stan­dard way of ini­tial­iz­ing a new Git repos­i­to­ry is to run git init. The direc­to­ry in which you do this will be become the Work­ing Tree for the repository.

As part of the ini­tial­iza­tion process, Git cre­ates a .git direc­to­ry (which his hid­den by default because of the . in the name) that con­tains the repos­i­to­ry itself. This is brains of the repos­i­to­ry; it’s where Git tracks your changes, stores com­mit objects, refs, etc. You prob­a­bly only rarely inter­act with that hid­den directory.

Okay, so all of this is to lay the ground­work for under­stand­ing a bare Git repos­i­to­ry. What the heck is it?

A bare Git repos­i­to­ry is a repos­i­to­ry that is cre­at­ed with­out a Work­ing Tree. Go ahead and cre­ate one to see.

$ git init --bare .

Run ls on that direc­to­ry and you won’t see a Work­ing Tree but just the con­tents of what is typ­i­cal­ly in the .git directory.

Why this setup?

A bare Git repos­i­to­ry is typ­i­cal­ly used as a Remote Repos­i­to­ry that is shar­ing a repos­i­to­ry among sev­er­al dif­fer­ent peo­ple. You don’t do work right inside the remote repos­i­to­ry so there’s no Work­ing Tree (the files in your project that you edit), just bare repos­i­to­ry data.

And that’s it.