What's the difference between git clone --mirror and git clone --bare
git clone帮助页面上有关于
Set up a mirror of the remote repository. This implies
--bare .
但没有详细介绍
区别在于,使用
新文档几乎说明了所有这些:
--mirror 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 branches, notes etc.) and sets up a refspec configuration such that all these refs are overwritten by agit remote update in the target repository.
我的原始答案还指出了裸克隆和普通(非裸)克隆之间的区别-非裸克隆设置了远程跟踪分支,仅为
假设原点有几个分支(
-
git clone origin-url (非裸露):您将复制所有标签,本地分支master (HEAD) 跟踪远程分支origin/master ,以及远程分支origin/next ,origin/pu 和origin/maint 。设置了跟踪分支,因此,如果您执行git fetch origin 之类的操作,则会按您期望的方式提取它们。任何远程分支(在克隆的远程中)和其他引用都将被完全忽略。 -
git clone --bare origin-url :您将获得所有已复制的标签,本地分支master (HEAD) ,next ,pu 和maint ,没有远程跟踪分支。也就是说,所有分支均按原样复制,并且设置为完全独立,不希望再次获取。任何远程分支(在克隆的远程中)和其他引用都将被完全忽略。 -
git clone --mirror origin-url :这些引用的最后一个将被原样复制。您将获得所有标签,本地分支master (HEAD) ,next ,pu 和maint ,远程分支devA/master 和devB/master ,其他引用refs/foo/bar 和refs/foo/baz 。一切都与克隆的遥控器完全相同。设置了远程跟踪,因此,如果您运行git remote update ,则所有引用都将从原点覆盖,就像您刚刚删除镜像并将其重新克隆一样。正如文档最初所说的,它是一面镜子。它应该是功能相同的副本,可以与原始副本互换。
1 | $ git clone --mirror $URL |
是...的简写
1 2 | $ git clone --bare $URL $ (cd $(basename $URL) && git remote add --mirror=fetch origin $URL) |
(直接从这里复制)
当前手册页的显示方式:
Compared to
--bare ,--mirror not only maps local branches of the source to local branches of the target, it maps all refs (including remote branches, notes etc.) and sets up a refspec configuration such that all these refs are overwritten by agit remote update in the target repository.
我今天使用git-2.0.0进行的测试表明--mirror选项不会复制钩子,配置文件,描述文件,信息/排除文件,至少在我的测试用例中是一些引用(我不这样做)不能理解。)我不会将其称为"功能相同的副本,可以与原始副本互换"。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | -bash-3.2$ git --version git version 2.0.0 -bash-3.2$ git clone --mirror /git/hooks Cloning into bare repository 'hooks.git'... done. -bash-3.2$ diff --brief -r /git/hooks.git hooks.git Files /git/hooks.git/config and hooks.git/config differ Files /git/hooks.git/description and hooks.git/description differ ... Only in hooks.git/hooks: applypatch-msg.sample ... Only in /git/hooks.git/hooks: post-receive ... Files /git/hooks.git/info/exclude and hooks.git/info/exclude differ ... Files /git/hooks.git/packed-refs and hooks.git/packed-refs differ Only in /git/hooks.git/refs/heads: fake_branch Only in /git/hooks.git/refs/heads: master Only in /git/hooks.git/refs: meta |
GitHub文档中有关复制存储库的细微差别说明:
As with a bare clone, a mirrored clone includes all remote branches and tags, but all local references will be overwritten each time you fetch, so it will always be the same as the original repository.
我添加一张图片,显示镜和裸露之间的差异。

左边是裸露的,右边是镜子。您可以清除,镜像的配置文件具有
克隆将从远程服务器复制参考,并将其填充到名为"这些是远程服务器具有的参考"的子目录中。
镜像从远程复制参考,并将其放入自己的顶层-用远程替换其自身的参考。
这意味着,当有人从您的镜像中拉出并将镜像的ref塞入其子目录时,他们将获得与原始镜像相同的ref。从最新镜像中获取的结果与直接从初始存储库中获取的结果相同。
1 | $ git clone --bare https://github.com/example |
此命令将使新的本身成为$ GIT_DIR。 而且,远程的分支头直接复制到相应的本地分支头,而无需映射。 使用此选项时,不会创建远程跟踪分支或相关的配置变量。
1 | $ git clone --mirror https://github.com/example |
与裸克隆一样,镜像克隆包括所有远程分支和标记,但是每次提取时所有本地引用(包括远程跟踪分支,注释等)都将被覆盖,因此它始终与原始存储库相同。 。