A bare repository is one in which local development is not allowed.
This is useful if you are setting up a server to host your source code, or perhaps implementing a backup strategy where your source code is replicated to a safe, off-site location. You can think of the Git repositories hosted on GitHub or GitLab as bare repositories, as no local development happens directly on the GitHub or GitLab servers. They are bare git repos whose sole purpose is to enable the distributed sharing of code.
Types of git bare repos
There are two ways to create a bare git repo:
- Clone an existing repository with the git clone –bare switch
- Create a new bare git repo with the git init –bare switch
Obviously, the bare git init approach is used when you are starting a brand new project. The clone is used when there is Git repo that is being actively developed and you want to create a backup or extra node point.
Create bare git repo commands
The actual commands used in the bare Git repo example are as follows:
[email protected]:~$ git clone --bare https://github.com/cameronmcnz/my-github-repo.git [email protected]:~$ git init --bare .
There is no need to have an active development workspace or working tree on a Git repo that is acting purely as a remote Git hosting node. Doing so would just create a need to run Git clean up routines in the future. In such situations, it makes sense to create a git bare repo.