Convert a Git Repo to a Bare Repo
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:
- Take a “normal” git repository
- Move the .git directory to another location
- 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.