What is a bare git repository?

By Jon Saints - 26 Jan 2011

What is the difference between a repository created using the “git init” command and the “git init –bare” command?

Repositories created with “git init” command contain 2 things: the .git folder repository (or code history) and also real life working copies of your source code files. You can think of this type of repository as a working directory. Its a folder with code history stored in .git folder and all the source files as well. You can work in this directory changing source files and save your changes using the “git add” and “git commit” commands.

Bare repositories contain only the .git folder and no working copies of your source files. If you “cd” into a bare repository you find only the .git folder and nothing else. A bare repository strictly contains the version history of your code.

Why use one or the other?

Well, a working repository is for just that… working. Its where you will actually edit files, add files, delete files to create your project saving your changes to the local .git repo along the way. If you are starting a project in a folder which will contain your code as well as a git repo for tracking changes use “git init”. Also if you “git clone” a repository from some one else you will be given a working repository with the .git folder and copies of the working files.

A bare repository is for… sharing on a centralized server. Bare repositories are shared repos where developers can send their local changes from their working copies of projects to the world or to the rest of their team. By using the “git push” command, you are able to send changes in your local working copies of a project to a centralized shared bare repository. Other developers can then “git pull” to receive the changes that you made. If you are collaborating with a team of developers or you need to work on a project from multiple computers , then a bare git repository is what you need in between to coordinate the distributed development.

To summarize: the working directory created with “git init” or “git clone” is my local copy of a project. Its where I add my changes to a project’s code files and test. After I am happy I “git add” and “git commit”. Then I “git push” to a bare repository, usually on another server, so that other developers can access my changes. When I want to update my local working copy I “git pull” to receive the changes that other developers have made.

Discussion & Comments

comments powered by Disqus