请问我如何从另一个代码库分叉(fork)我已经在GitHub上拥有的存储库?

huangapple go评论50阅读模式
英文:

Please how can I fork a repo which I already have in my GitHub but from another codebase

问题

GitHub 不允许我分叉这个代码库,因为我在 GitHub 上已经有一个类似的项目,但是来自不同的代码库。我尝试点击分叉,但是收到了一个异常,指出“无法创建更多的分叉。这些分叉已经存在。”

英文:

There is this codebase that I want to fork but GitHub won't allow me to do that because I already have a similar project in my GitHub but from a different codebase.

I tried clicking on fork but I received an exception stating "No more forks can be created. These forks already exist."

答案1

得分: 1

如果我理解正确,您想从两个不同的存储库获取提交。一个是您已经分叉的存储库“origin”。另一个来自另一个用户,他也分叉了它,但GitHub不允许您引用多个分叉。

如果您想从另一个Git存储库获取更改,并且您已经分叉了一个存储库,那么在克隆它时,已经添加了远程origin。您可以在本地git存储库中添加一个新的远程引用。

请注意,GitHub不会将其视为两个分叉,实际上,远程引用只是本地的。我不确定您将如何管理它,也不建议这样做,但在这种情况下,我会将存储库克隆到本地,然后添加一个新的远程

git remote add <new-name-to-the-remote> <link-to-repository>

这样,您可以引用它们两个。远程origin将指向当前的分叉,而您添加的新远程(随便起名字,比如repo-of-user-xanother-repo)将指向另一个分叉。现在,如何处理它们取决于您想要做什么。例如,如果您想要从其他存储库检出一个分支,请参考问题https://stackoverflow.com/a/1783426/2084091(具体是引用的答案),如果您想要将更改拉入当前分支,请查看问题https://stackoverflow.com/q/41644776/2084091。

英文:

If I understand you well, you want to take commits from two different repositories. One is the repository origin which you already forked. The other is from another user which forked it as well, but GitHub will not allow you to refer to multiple forks.

If you want to take the changes from another Git repository, and you have already forked one, then you already have the remote origin added when you clone it. What you can do is to add a new remote reference in your local git repo.

Notice GitHub will not recognize it as two forks, in fact, the remote will be just locally. Not sure how you would manage it, and I do not recommend it by myself, but what I would do in this case would be to clone the repository locally, then add a new remote:

git remote add &lt;new-name-to-the-remote&gt; &lt;link-to-repository&gt;

In this way you can refer to both of them. The remote origin will point to the current fork, and the new remote you add (call it what you want, say repo-of-user-x or another-repo). Now, how to handle them depends on what you want to do. For example, if you want checkout a branch from the other repo, checkout the question https://stackoverflow.com/a/1783426/2084091 (specifically the refered answer), and if you want to pull the changes into your current branch, checkout the question https://stackoverflow.com/q/41644776/2084091.

huangapple
  • 本文由 发表于 2023年2月23日 21:27:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/75545493.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定