Ali Ali - 6 months ago 67
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
flag during clone prevents checkout of
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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download