Gregg's MOTD

Tips & Tricks that I've Encountered Over the Years...

Convert a Git Repo to a Bare Repo

August 12, 2023 — Gregg Szumowski

If you have a git repository that you haven’t cloned from a remote location, i.e., one that was created locally, it is easy to convert it to a bare repository. This process describes how to:

  1. Take a “normal” git repository
  2. Move the .git directory to another location
  3. Convert it to a bare repository

Suppose you have a git repository called repo. To convert it to a bare repository, execute the following commands:

cd repo
mv .git ../repo.git # renaming just for clarity
cd ..
rm -fr repo
cd repo.git
git config --bool core.bare true

Now you can clone it like a “normal” repository:

$ cd ..
$ git clone repo.git myrepo
$ cd myrepo/
$ ls
file-1.txt file-2.txt file-3.txt file-4.txt file-5.txt
$ git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean
$

Please note that repositories from a remote location do not have all of their git branch contents and history stored locally, so doing this to a repository cloned from a remote will result in a repository that will be missing data.

Tags: cli, git, motd