A bare repository is one in which local development is not allowed.
This type of repository is useful if you are setting up a server to host your source code or perhaps implementing a backup strategy that replicates your source code 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. These 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, you should use the bare git init approach when you are starting a brand new project. And use the clone when a Git repo is active and you want to create a backup or extra node point.
Create bare Git repo commands
Use these commands, as shown in the bare Git repo example:
git-clone@bare:~$ git clone --bare https://github.com/cameronmcnz/my-github-repo.git git-clone@bare:~$ git init --bare .
You don’t need to have an active development workspace or working tree on a Git repo that is acting purely as a remote Git hosting node. This would just force you to run Git clean up routines in the future. In such situations, it makes sense to create a bare Git bare repo.