Convert a normal Git repository to a bare one

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

Move, config and rm by hand

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  


  • Use && instead of ; in case mv fails!
  • rm -rf repo is not a must, if you need the repo pls keep it intact.
  • -C <path> run as if git was started in <path> instead of the current working directory. This option is very useful.
  • In git config command which is not involved with work tree—Another example of this restriction is here, you can also use --git-dir=repo.git
  • 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.

Git clone –bare

This handle all the internal settings by Git itself.

git clone --bare --local repo repo.git

This method comes from Git FAQ.


  • In effect, --local can be omitted as this reason.
  • With --bare, neither remote-tracking branches nor the related configuration variables are created.

Git clone –mirror

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 --bare, --mirror not 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 update in the target repository.


  • With --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.

本作品采用《CC 协议》,转载必须注明作者和本文链接
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

访问:11.4 万