简体   繁体   English

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

[英]Copy/fork a git repo on github into same organization

I have a repo on github that contains a web application that's deployed to two different domains.我在 github 上有一个存储库,其中包含一个部署到两个不同域的 Web 应用程序。 The application has slight logic forks here and there to behave differently depending on which domain it's deployed to.该应用程序在这里和那里有轻微的逻辑分支,根据它部署到的域,其行为会有所不同。

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. Github 不会让我将它分叉到同一个组织中。 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.搜索“git duplicate repo”表明我应该直接克隆并镜像推送它,但这似乎是为了让两个存储库保持同步,我不想这样做。

What's the best way to go about this?解决这个问题的最佳方法是什么? I'd like to preserve the old commit history in the new copy if possible.如果可能的话,我想在新副本中保留旧的提交历史。

Just create a new repository and push to it from your working copy:只需创建一个新存储库并从您的工作副本推送到它:

git clone git@github.com:me/myrepo-original
cd myrepo-original
git remote set-url origin git@github.com: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相同。

If you do not need the fork relation (eg 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 do want to make it a fork, contact Github support (support@github.com or https://github.com/support ), and they will create a fork in the same organization for you.如果你确实想把它做成一个分支,请联系 Github 支持(support@github.com 或https://github.com/support ),他们会在同一个组织中为你创建一个分支。 (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.) (他们对此也不挑剔,您只需为 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 支持表示支持当前/不再在您的帐户中设置第二个分支。

GitHub recently posted an article about possible alternatives to forking a repo into the same account. GitHub 最近发布了一篇关于将 repo 分叉到同一帐户的可能替代方案的文章。 You can read that article here . 你可以在这里阅读那篇文章

Use Github's Import Repository option on the + menu on top of the page or just open使用页面顶部+菜单上的 Github 的Import Repository选项或直接打开

https://github.com/new/import https://github.com/new/import

This creates a new repository with the exact contents of the copied repository.这将创建一个新的存储库,其中包含复制的存储库的确切内容。 The downside (the same as for git commands answer by Iarsks ) is that it doesn't count as a fork for Github.缺点(与Iarsks 回答的 git 命令相同)是它不能算作 Github 的分支。

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 git@github.com: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

I know this is a super old thread, but I stumbled across it looking for the the answer and subsequently found a better way:我知道这是一个超级旧的线程,但我偶然发现它寻找答案并随后找到了更好的方法:

Make the repo you want to copy a template repo.制作要复制模板 repo 的 repo。 It is a check box at the top of the repository settings.它是存储库设置顶部的复选框。 After you do this, there will be a big green button labeled "Use this template" at the top of the repo next to the Code button.完成此操作后,在代码按钮旁边的代码库顶部将有一个标有“使用此模板”的绿色大按钮。 Click that, and it will make a copy of the repo in whichever account you want.单击它,它将在您想要的任何帐户中复制回购。

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.如果 repo 是私有的,它也将在新组织中保持私有。 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 提高回原始存储库。

You can mark the first repo as a Template (in settings) and then "Use" that template repo when you create a new repo.您可以将第一个存储库标记为模板(在设置中),然后在创建新存储库时“使用”该模板存储库。 It's not exactly a fork, but functionally equivalent in some respects.它不完全是一个分叉,但在某些方面在功能上是等效的。

Github won't let me fork it into the same organization Github 不会让我将它分叉到同一个组织中

GitHub does let you fork within the same organisation, since June 2022.自 2022 年 6 月以来,GitHub确实允许您在同一组织内进行分叉。

Improved innersource collaboration and enterprise fork policies 改进的内部资源协作和企业分支策略

Previously, three aspects of repository forks caused friction to innersource collaboration and administration:以前,存储库分叉的三个方面对内部资源协作和管理造成了摩擦:

  1. Repositories could not be forked within a single organization.存储库不能在单个组织内分叉。
  2. Repositories with internal visibility could not be forked to an organization.无法将具有内部可见性的存储库分叉给组织。
  3. Enterprise owners lacked control over where repositories could be forked.企业所有者无法控制可以在哪里分叉存储库。

These obstacles have been addressed with the following new features.这些障碍已通过以下新功能得到解决。 We're always looking for new ways to improve repository collaboration and we welcome your ideas .我们一直在寻找改进存储库协作的新方法, 我们欢迎您的想法

Fork a repository to the same organization as its parent将存储库分叉到与其父级相同的组织

Previously, a repository could be forked only to a different organization or user account.以前,存储库只能派生到不同的组织或用户帐户。

Now, a repository can be forked to the same organization as its parent repository , addressing situations where people are working in one organization and don't want to fork a repository to a different organization or user account.现在,可以将存储库分叉到与其父存储库相同的组织,从而解决人们在一个组织中工作并且不想将存储库分叉到不同的组织或用户帐户的情况。

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. 似乎更清洁,更容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM