An introduction to bare repos

/ Jack Lot


A bare repository is a Git repository with the project files stripped out. Just Git’s internal database. Bare repos have been around since the beginning of Git, but the way developers are starting to use them today is something they were never technically designed for… with worktrees.

The cheatsheet

Creating a bare repo

git clone --bare <repository-url> <folder-name>

Adding the --bare flag tells Git to clone only Git’s administrative backend without checking out any project files.

Tips for cloning bare repos

Use the same clone command above, but add /.git to the destination path:

git clone --bare <repository-url> <project-name>/.git

Instead of exploding all the administrative files into the root of your project folder, adding .git to the path contains them the way a traditional repository does (inside a .git/ folder)

After cloning, you can create a worktree in the root of your project folder:

git worktree add <name>

This command creates a worktree folder with its own working directory, AND a checkout of the actual project files. Navigate into the worktree folder you just created and everything behaves like you’d normally expect.

Why were bare repos created?

The original answer is that you put one on a server. Git is distributed, so when a team collaborates there needs to be an authoritative copy everyone can push and pull from. That central copy does not need a working directory, because nobody should be editing files directly on the server: you do not want two developers’ pushes fighting over checked-out files. A bare repo is exactly the right shape: a Git database with no working directory, just version history. If you have ever pushed to GitHub or GitLab, you have been interacting with a bare repo.

Going further


TAGS: videos, git, tutorials