gitversion-controlgit-clonegit-baregit-non-bare-repository

How to convert a normal Git repository to a bare one?


How can I convert a 'normal' Git repository to a bare one?

The main difference seems to be:


Solution

  • In short: replace the contents of repo with the contents of repo/.git, then tell the repository that it is now a bare repository.

    To do this, 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
    

    Note that this is different from doing a git clone --bare /path/to/repo to a new location (as described here).

    Consider this scenario

    If that's your intention, that's fine. If you needed a mirror of the remote/origin, this is not the way.