如何从现有存储库中的分支创建新的 GitHub 存储库?

编程入门 行业动态 更新时间:2024-10-22 05:09:11
本文介绍了如何从现有存储库中的分支创建新的 GitHub 存储库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有 ma​​ster 和 new-project 分支.现在我想基于 new-project 分支用它的 master 创建一个全新的 repo.

I have master and new-project branches. And now I'd like to create a brand new repo with its master based on the new-project branch.

背景:我有一个包含三个独立应用程序的存储库.它不是这样开始的.存储库中最初只有一个应用程序.然而,随着时间的推移,业务需求发生了变化.一个应用程序变成了两个(旧版本和重写版本).添加了一个 Web 服务.单独的分支用于包含三个项目.但是,它们不共享任何代码.因此,将它们拆分为自己的存储库会更简单.

Background: I have one repository which contains three independent applications. It didn't start out this way. There was originally just one app in the repo. Over time, however, business needs have changed. One app became two (a legacy version and a re-write.) A web service was added. Separate branches were used to contain the three projects. However, they don't share any code. And so it'd be simpler to have them split out into their own repos.

推荐答案

我从@user292677 的想法开始,并对其进行改进以解决我的问题:

I started with @user292677's idea, and refined it to solve my problem:

  • 在 github 中创建 new-repo.
  • cd 到您要从中提取的旧存储库的本地副本,该副本设置为跟踪将成为 new-repo 的 new-project 分支的主人.
  • $ git push github/accountname/new-repo.git +new-project:master
  • Create the new-repo in github.
  • cd to your local copy of the old repo you want to extract from, which is set up to track the new-project branch that will become the new-repo's master.
  • $ git push github/accountname/new-repo.git +new-project:master
  • 新的 Github 存储库已完成.结果是;

    The new Github repo is finished. The result is;

    • 一个名为 new-repo 的新 Github 存储库,
    • 其master对应于旧repo的new-project,与
    • 保留所有历史记录.
    • a new Github repository named new-repo,
    • whose master corresponds to the old repo's new-project, with
    • all history preserved.

    事实上,我发现通过使用这种方法,我可以使用精心挑选的分支创建新的存储库,并根据需要重命名:

    In fact, I found that by using this method, I could create the new repo with a hand-picked selection of branches, renamed as I wanted:

    $ git push git@github:accountname/new_repo +new-project:master +site3a:rails3

    结果是,先前存在的 site3a 分支现在也移动到新的存储库中,并将显示为 rails3.这非常有效:网络图显示了新的 ma​​ster 和 rails3,它们具有完整的历史记录并且它们之间的关系正确.

    The result is that the pre-existing site3a branch is now also moved to the new repo and will appear as rails3. This works really well: the network diagram shows the new master and rails3 with full history and in their correct relationship to each other.

    2013-12-07 更新:将其用于另一个项目,并验证此配方仍然有效.

    Update 2013-12-07: Used this with another project, and verified that this recipe still works.

    更新 2018-01-11:更新了第 3 步,以使用 GitHub 推荐的 https 协议.配方仍然有效.

    Update 2018-01-11: Updated step 3. to use GitHub recommendation for https protocol. Recipe still works.

    更多推荐

    如何从现有存储库中的分支创建新的 GitHub 存储库?

    本文发布于:2023-11-28 16:32:33,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1643144.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:分支   库中   GitHub

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!