【问题标题】:Transfer "authoritative" git repository from Github to a private github将“权威”git 存储库从 Github 转移到私有 github
【发布时间】:2012-05-07 21:09:49
【问题描述】:

我的任务是将我们的存储库从公共 github 移动到本地网络上的私有 github 实例。

我的想法是移动它们

git clone --bare <github-repo-url>
git push --mirror <local-github-url>

在过渡期间,我应该能够从爸爸 github 上的存储库中自行更新镜像。 (或者我会吗?我还没有在 UI 中找到执行更新的命令。)

那我就删除“权威”的github仓库,镜像就变成权威了。

但是这是怎么发生的呢?是不是每个开发者都需要在.git/config中修改“origin”的url?

镜像是否会接受来自其克隆父级的非更新推送?

【问题讨论】:

  • 更多信息:“local-github-url”是真正的 Github。这是一项私有的 Github Enterprise 服务。我没有对私有 Github 的 shell 或 crontab 访问权限。

标签: git github


【解决方案1】:

您的过程几乎是完美的。唯一的问题是初始克隆中缺少--mirror 参数。

# create the private repo
ssh private-server
mkdir -p /path/to/shared/repos
git init --shared={whatever makes sense for your environment} /path/to/shared/repos/internalrepo.git
exit
# go to github.com and make the public repo readonly
# create a local mirror
git clone --bare --mirror $Github-URL github.git
# now the local repo github.git contains all the stuff from the github repo
cd github.git
git push --mirror $Private-URL
# Tell all developers to execute `git remote set-url origin  $Private-URL`
# Done

我不会让 github 存储库对更改开放,因为项目中的每个人都不清楚哪个存储库现在是正确的存储库。如果你在 server-repo 上运行,你仍然可以这样做

ssh private-server
cd /path/to/shared/repos/internalrepo.git
git remote add --mirror github $Github-URL

然后定期(例如在 cron 作业中)

git fetch github # get new commits from github
git remote prune github # drop branches, which are now deleted in the github repo

编辑

您也可以使用本地镜像进行交换。但是没有简单的自动化过程,因为 git 既不能决定如何处理已删除的分支,也不能决定如何处理分歧的分支。所以你需要保留一个工作存储库,定期从以前的 github-repo 获取内容,从内部 repo 获取内容,解决不同的历史并将这些内容推送回内部 repo。

【讨论】:

  • 鲁迪,很好的答案!但是,它假定私有 repo 位于我有 shell/crontab 的机器上。就我而言,私有仓库位于防火墙内的“Github Enterprise”实例上。除了通过 git 和网站,我无法直接访问私有存储库。
  • 我还没有看到 GHE 的解决方案。甚至 GHE 网站上的一些讨论也被删除了。
【解决方案2】:

最简单的过程是开发人员克隆新的(私有)存储库并从那里继续。
如果他们在以前的存储库中有任何待处理的更改,他们可以将这些更改导出为 补丁 并将它们应用到新的本地克隆存储库中,然后再将它们推回新的 origin。 (见What is the difference between 'git format-patch' and 'git diff'?和git format-patch man)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-08-08
    • 1970-01-01
    • 2019-02-18
    • 2020-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-01
    相关资源
    最近更新 更多