`git remote add --mirror=fetch` 会生成与 `git clone --mirror` 相同的 repo 吗?

Would `git remote add --mirror=fetch` make same repo with `git clone --mirror`?

如果我想复制一个 repo,我会使用它。

git clone --mirror $SRC $DST

但是此命令要求 $DST 中不存在回购协议。这通常没问题,但如果我想从多个进程同时发出 Git 命令,它可能会导致一些竞争条件,因为在执行命令之前不存在可锁定的文件对象。

如果我只想跳过 $DST 的存在性测试,我想我可以做到

mkdir -p $DST
cd $DST
git init --bare 
git remote add origin --mirror-=fetch $SRC 2>/dev/null || true
git remote update

这会生成与 git clone --mirror $SRC $DST 完全相同的回购协议吗?

如果您查看 test done for a git clone --mirror,您会看到一个镜像克隆是:

  • a fetch refspec 设置为 +refs/*:refs/*
  • a git config --bool remote.origin.mirror 设置为 true

如果在您的 git 远程命令后满足这些条件,那么是的,那将等同于镜像克隆。