Convert a normal Git repository to a bare one
In short: replace the contents of
repo with the contents of
repo/.git, then tell the repository that it is now a bare repository.
mv repo/.git repo_manual.git && git -C repo_manual.git config --type bool core.bare true && rm -rf repo
rm -rf repois not a must, if you need the
repopls keep it intact.
-C <path>run as if git was started in
<path>instead of the current working directory. This option is very useful.
git configcommand which is not involved with work tree—Another example of this restriction is here, you can also use
- Use –type to canonicalize outgoing (config) values. If you don’t set core.bare to true, you can still use a lot of commands that require a working directory such as
git add. It’s likely end up in a mess.
- The problem with the above process is that it doesn’t take into account future internal changes of Git, but it retains all the configuration variables and remote-tracking branches.
This handle all the internal settings by Git itself.
git clone --bare --local repo repo.git
This method comes from Git FAQ.
- In effect,
--localcan be omitted as this reason.
--bare, neither remote-tracking branches nor the related configuration variables are created.
git clone --mirror repo repo.git
--mirror is not equivalent to
--bare per the docs:
Set up a mirror of the source repository. This implies
--bare. Compared to
--mirrornot only maps local branches of the source to local branches of the target, it maps all refs (including remote-tracking branches, notes etc.) and sets up a refspec configuration such that all these refs are overwritten by a
git remote updatein the target repository.
--mirror, remote-tracking branches are retained but the related configuration variables are lost.
We can understand the detailed differences if we compare the bare repositories.