Ali Ali - 1 month ago 7
Git Question

How to convert a git repo to a bare repo

When a repository is cloned by using simple

git clone repo
, the master branch is automatically checked out. If after this automatic checkout, I want to delete all files checked out and turn the clone in to a bare clone, how can I achieve this? Are there configurations within the .git folder that I can modify to accomplish this?

Side note: I know that specifying the
--no-checkout
or
-n
flag during clone prevents checkout of
HEAD
and keeps the repository bare.
If I delete the files that are checked out, those files will be shown as deleted when running
git status
.

Answer Source

git clone --no-checkout doesn't give a bare repository, it just leaves the work tree and index empty. git status after such a clone will say that all files have been staged for deletion.

A bare repository is one with core.bare = true (and a bare repository made with git clone --bare will also not have any remote refs). You can do git config core.bare true to flip this bit. Then remove the work tree and index, and possibly rename the directory from repo/.git to repo.git.