git 将 Github fork 添加到现有存储库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7210273/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 05:54:21  来源:igfitidea点击:

Add Github fork to existing repository

gitgithubfork

提问by Mark Nichols

I setup an Octopress project following the given instructions (http://octopress.org/docs/setup/) which have you create a Github repository, and create a local repository on your machine. On your local machine you add a remote to the original Octopress repository and then issue a "git pull" command. Then you add a remote to your Github repository so you can push your changes to your repository.

我按照给定的说明 (http://octopress.org/docs/setup/) 设置了一个 Octopress 项目,您可以在其中创建一个 Github 存储库,并在您的机器上创建一个本地存储库。在您的本地机器上,您将远程添加到原始 Octopress 存储库,然后发出“git pull”命令。然后您将远程添加到您的 Github 存储库,以便您可以将更改推送到您的存储库。

All of this works as far as it goes, but it doesn't create a fork of the original project, meaning there's no obvious (to a newbie) way to issue a pull request to the original Octopress repository.

就目前而言,所有这些都有效,但它不会创建原始项目的分支,这意味着没有明显的(对新手)方式向原始 Octopress 存储库发出拉取请求。

Is there a way for me to add a fork of the original Octopress repository to my instance of that repository on Github?

有没有办法让我将原始 Octopress 存储库的分支添加到 Github 上该存储库的实例中?

If there isn't a way, can I safely delete my Github instance of Octopress, fork the original on Github, and then add a new remote from my local repository to the newly forked Octopress?

如果没有办法,我可以安全地删除我的 Octopress 的 Github 实例,在 Github 上分叉原件,然后从我的本地存储库添加一个新的远程到新分叉的 Octopress 吗?

采纳答案by Karl Bielefeldt

Although people tend to think of their repo on Github as the "official" one, remember that's a social distinction and not a technical one. From git's point of view every repo is on equal terms. That means as long as you have pulled every commit into your local repo, you can safely delete the one on Github. Then just fork the Octopress project on github, set it up as a remote on your local repo, and push. Git doesn't care which repo you originally got any given commit from. It "just works."

尽管人们倾向于将他们在 Github 上的存储库视为“官方”存储库,但请记住,这是一种社会区别而非技术区别。从 git 的角度来看,每个 repo 都是平等的。这意味着只要您将每个提交都拉入本地存储库,您就可以安全地删除 Github 上的那个。然后只需在 github 上 fork Octopress 项目,将其设置为本地存储库上的远程,然后推送。Git 不关心你最初从哪个仓库获得任何给定的提交。它“只是有效”。

回答by Barend

I'm unaware of any way to turn your blank github copy into a github fork after the fact, so

我不知道有什么方法可以在事后将你的空白 github 副本变成 github 分支,所以

If there isn't a way, can I safely delete my Github instance of Octopress, fork the original on Github, and then add a new remote from my local repository to the newly forked Octopress?

如果没有办法,我可以安全地删除我的 Octopress 的 Github 实例,在 Github 上分叉原件,然后从我的本地存储库添加一个新的远程到新分叉的 Octopress 吗?

is the way to go. Delete your own github repository, hit the fork button on the octoprocess repository and clone your fork to your local machine.

是要走的路。删除您自己的 github 存储库,点击 octoprocess 存储库上的 fork 按钮并将您的 fork 克隆到您的本地机器。

If you've already made any changes that you with to keep, I'd say that using git format-patchto store them as a series of patch files and git apply-patchto apply those on a clone of your new repository is probably easier than using the old one as a remote (on your local machine).

如果您已经进行了任何需要保留的更改,我会说使用git format-patch将它们存储为一系列补丁文件并将git apply-patch它们应用于新存储库的克隆可能比使用旧存储库更容易远程(在您的本地机器上)。

回答by Onceler

If I understand the OP. They have a Git repo, and they have now decided that it should have forked another repo. Retroactively they would like it to become a fork, without disrupting the team that uses the repo by needing them to target a new repo.

如果我了解 OP。他们有一个 Git 存储库,现在他们决定应该分叉另一个存储库。追溯起来,他们希望它成为一个分叉,而不会因为需要他们瞄准一个新的 repo 而干扰使用 repo 的团队。

I've thought about renaming a new repo into place. so if the team current clones, and fetchs, and pulls example.git

我已经考虑过将新的 repo 重命名到位。因此,如果团队当前克隆、获取和拉取example.git

  1. setup a new repo that is a fork, example_fork.git
  2. rename example.git to example_deprecated.git
  3. quickly rename example_fork.git to example.git.
  1. 设置一个新的分叉 repo,example_fork.git
  2. 将 example.git 重命名为 example_deprecated.git
  3. 快速将 example_fork.git 重命名为 example.git。

I've heard that anyone who already had a clone would be met with an error of sorts (so that doesn't avoid the inconvenience as well as I would hope)

我听说任何已经拥有克隆的人都会遇到各种各样的错误(所以这并不能像我希望的那样避免不便)

I've also seen suggestions to use Force Push: Marking a repo as a fork in github, after the fact

我还看到了使用强制推送的建议:事后将 repo 标记为 github 中的分叉

.

.

But now I'm wondering if topic of discussion is more accurately worded as "setting the upstream remote of an existing repository". Discussed here: Adding remote upstream to git repo on bit bucket

但现在我想知道讨论的主题是否更准确地表述为“设置现有存储库的上游远程”。此处讨论: 将远程上游添加到位桶上的 git repo

based on the feedback provided here: What does 'git remote add upstream' help achieve?I think it would basically allow retroactive forking like I want, and like I think the OP is asking for.

基于此处提供的反馈:“git remote add upstream”有助于实现什么?我认为它基本上允许像我想要的那样追溯分叉,就像我认为 OP 所要求的那样。

I have not tried it yet.

我还没有尝试过。