[英]Fully fork a git repo?
从这里的大量答案和博客文章中,我还没有设法将我想知道的内容拼凑起来,所以我问这个问题:
如何分叉git repo,以便获得上游的所有分支和标签?
我试过的是:
git init
git remote add origin <ORIGIN_URL> # i.e. my repo
git remote add upstream <UPSTREAM_URL> # i.e. the repo I want to fork
git fetch upstream
git push --all origin
但是当我希望它能工作时,最后一行失败。 我得到这个:
$ git push --all origin
No refs in common and none specified; doing nothing.
Perhaps you should specify a branch such as 'master'.
fatal: The remote end hung up unexpectedly
error: failed to push some refs to <ORIGIN_URL>
有任何想法吗?
编辑:
也许您可以将这个问题想成“当您单击fork按钮时GitHub实际上会做什么?”,因为这就是我要复制的行为。
试一面镜子:
git clone --mirror
这样,就创建了远程(命名为origin
),而没有分支的名称空间。 IOW,镜像中的refs / heads / master完全对应(并绑定到)原始存储库中的refs / heads / master。
现在仅使用此存储库,而不是原始的上游存储库。 如果您想更新镜像,请在其中执行以下操作:
cd upstream-mirror.git && git --bare fetch upstream
警告:如果您推入镜像,修改上游分支,上游存储库和镜像将分开。 和push(不带-f
选项)将失败,以防止这种情况。
镜像实际上是上游存储库的精确镜像,您(作为所有者)可以选择对其进行修改。
这是我想出的最好方法,可以做我想做的事情,它似乎可以正常工作,并且具有与GitHub相似的行为:
git clone --mirror <UPSTREAM> myrepo
cd myrepo
git remote rename origin upstream
git remote add origin <MY_ORIGIN>
git push --all
git push --tags
然后调整.git/config
以更改upstream
远程服务器不再镜像,因为这肯定不是我现在想要的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.