Convert a Git Repo to a Bare Repo
Gregg
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 repomv .git ../repo.git # renaming just for claritycd ..rm -fr repocd repo.gitgit config --bool core.bare true
Now you can clone it like a “normal” repository:
$ cd ..$ git clone repo.git myrepo$ cd myrepo/$ lsfile-1.txt file-2.txt file-3.txt file-4.txt file-5.txt$ git statusOn branch masterYour 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.