gpt4 book ai didi

git - 将 "authoritative"git 仓库从 Github 转移到私有(private) github

转载 作者:太空狗 更新时间:2023-10-29 13:12:26 28 4
gpt4 key购买 nike

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

我的想法是用它们来移动

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

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

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

但是这是怎么发生的呢?每个开发人员都需要更改 .git/config 中“origin”的 url 吗?

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

最佳答案

您的流程近乎完美。唯一的问题是初始克隆中缺少 --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。

关于git - 将 "authoritative"git 仓库从 Github 转移到私有(private) github,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10345212/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com