If you’ve ever created a Git repository from scratch, you’re familiar with the git init command. It’ creates everything you need to support a fully fledged git based environment, along with a special spot known as the working tree or working directory where you can create files and write code.
What is a bare Git repository?
But what if you have a server where you simply want to manage a git repository, allow users to push and pull, but you have no interest in using that repository for ongoing development, branch creation or local commits? If that’s the case, you can use the git init bare command and create a bare Git repository. A bare Git repo has all of the capabilities of a non-bare repository, with the exception of the fact that it can’t be used to write code.
The command to create a git bare repository is as follows:
git init bare .
Git bare vs non-bare repos
If you inspect a bare git repo, you’ll notice that the .git folder you would see in a normal repository is missing. Instead, all of the content that would normally go in the .git folder of repo are in the right there in the root of the directory. This includes folders such as:
Furthermore, the following folders are missing when you issue the git init bare repo command:
By the way, the command to create a regular Git repo is as follows:
Git bare clone
It’s worth noting that you can also create a bare git repository through a clone. Just use the –bare switch with the git clone command and you will have a Git repository without a working tree.
git clone --bare
Why use a bare Git repo?
Of course, these fine details about the contents of the bare Git repository aren’t particularly pertinent to ongoing software development. This simply emphasizes the point that the git init bare command creates a repository that is a bit different from the norm, with the manifestation of that difference being the fact that you can’t write code in it, and there’s never a need to clean up Git worktrees or workspaces. A bare git repository is intended to be used as a remote repository where code is shared between members of the team. The bare git repo is not intended for local development.