将 github 上的 git repo 复制/分叉到同一组织中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22767617/
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-10 17:57:13  来源:igfitidea点击:

Copy/fork a git repo on github into same organization

gitgithubgit-fork

提问by jemminger

I have a repo on github that contains a web application that's deployed to two different domains. The application has slight logic forks here and there to behave differently depending on which domain it's deployed to.

我在 github 上有一个 repo,其中包含一个部署到两个不同域的 web 应用程序。应用程序在这里和那里有轻微的逻辑分支,根据它部署到的域而表现不同。

It's come to the point to where I want to split it into two separate repos, one for each domain.

到了我想将其拆分为两个单独的存储库的地步,每个存储库一个。

Github won't let me fork it into the same organization. Searching for "git duplicate repo" suggests I should bare clone and mirror push it, but that seems to be for keeping both repos in sync, which I don't want to do.

Github 不会让我把它分叉到同一个组织中。搜索“git重复存储库”建议我应该裸克隆并镜像推送它,但这似乎是为了保持两个存储库同步,我不想这样做。

What's the best way to go about this? I'd like to preserve the old commit history in the new copy if possible.

解决这个问题的最佳方法是什么?如果可能,我想在新副本中保留旧的提交历史记录。

回答by larsks

Just create a new repository and push to it from your working copy:

只需创建一个新的存储库并从您的工作副本推送到它:

git clone [email protected]:me/myrepo-original
cd myrepo-original
git remote set-url origin [email protected]:me/myrepo-new
git push origin master

Now you have a new repository, myrepo-new, which is identical to myrepo-original.

现在您有一个新的存储库,myrepo-new,它与myrepo-original.

回答by Nevik Rehnel

If you do not need the fork relation (e.g. you want some kind of decoupled alternate repo for whatever reason), duplicating the repo as outlines by your Google finds and larsks's answer is fine.

如果您不需要分叉关系(例如,无论出于何种原因,您都想要某种解耦的备用回购),则将回购复制为您的 Google 发现和 larsks 的答案的轮廓就可以了。

If you dowant to make it a fork, contact Github support ([email protected] or https://github.com/support), and they will create a fork in the same organization for you. (They're not picky about this either, you'll have just to provide an alternative name for the repo, as repo names within an account must be unique.)

如果您确实想将其作为一个分支,请联系 Github 支持([email protected]https://github.com/support),他们将在同一组织中为您创建一个分支。(他们对此也不挑剔,您只需为 repo 提供一个替代名称,因为帐户中的 repo 名称必须是唯一的。)



Update: User Steve Rice reports in the comments below that GitHub Support stated that support would not currently/no longer set up a second fork in your account.

更新:用户 Steve Rice 在下面的评论中报告说,GitHub Support 表示支持目前不会/不再在您的帐户中设置第二个分叉。

GitHub recently posted an article about possible alternatives to forking a repo into the same account. You can read that article here.

GitHub 最近发布了一篇关于将 repo 分叉到同一帐户的可能替代方案的文章。你可以在这里阅读那篇文章

回答by sarob

Use Github's Import Repositoryoption on the +menu on top of the page

在页面顶部+菜单上使用 Github 的导入存储库选项

This creates a new repository with the exact contents of the copied repository. The downside is that it doesn't count as a fork for Github.

这将创建一个新的存储库,其中包含复制的存储库的确切内容。缺点是它不能算作 Github 的分叉。

回答by Vinay Vemula

Another way would be to add the original repo, to be copied, as remote for our current repo.

另一种方法是添加要复制的原始仓库作为我们当前仓库的远程仓库。

#create a new repo in the org1 organization called myrepo-new

In your local terminal, run:

在本地终端中,运行:

git clone [email protected]:org1/myrepo-new
cd myrepo-new
git remote -v #shows current repo link on github as origin
git remote add name-for-remote https://github.com/org1/repo-old
git remote -v #shows repo-old as name-for-remote
git fetch  name-for-remote
git merge name-for-remote/branch-to-get-from-remote
#Now fix any conflicts if present
#If number of files/commits is very high, the desktop client may hang when you try to commit your changes after merge. Try switching to Git Shell if this happens.
git status 
git commit -m "commit message"
git push origin master

回答by csaboable

Alternative solution:

替代解决方案:

Create a new organisation and fork it there. If the repo is private, it will stay private in the new org as well. Then you can give access to external devs or whoever you want to the forked repo and they can raise PRs back to original repo.

创建一个新组织并在那里分叉。如果回购是私有的,它也将在新组织中保持私有。然后你可以访问外部开发人员或任何你想要分叉回购的人,他们可以将 PR 提升回原始回购。

回答by Ben Wilson

Couldn't you just duplicate the local folder, delete the git stuff:

你不能只是复制本地文件夹,删除git的东西:

rm -rf .git*

Then make a new repository in that folder? Seems cleaner and easier.

然后在该文件夹中创建一个新存储库?看起来更干净,更容易。