News Stay informed about the latest enterprise technology news and product updates.

What is a bare Git repository?

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, and 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 the capabilities of a non-bare repository, with the exception 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 the repo are in the right there in the root of the directory. This includes folders such as:

  • branches
  • config
  • description
  • HEAD
  • hooks
  • info
  • objects

Furthermore, the following folders are missing when you issue the git init bare repo command:

  • index
  • logs
  • refs
  • COMMIT_EDITMG

 
git init bare

The git init bare command creates a bare git repository for use as a remote server with which to share code.

By the way, the command to create a regular Git repo is as follows:

git init

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?

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.

After you issue a git init bare command, you won’t be able to write code in that repo, which also means you won’t have need to clean up Git worktrees or workspaces.

SearchAppArchitecture
SearchSoftwareQuality
SearchCloudComputing
SearchSecurity
SearchAWS
Close