简体   繁体   English

将“权威”git存储库从Github转移到私有github

[英]Transfer “authoritative” git repository from Github to a private github

My task is to move our repositories from public github to a private instance of github on our local net. 我的任务是将我们的存储库从公共github移动到我们本地网络上的github私有实例。

My thought is to move them with 我的想法是移动它们

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

During a transition time, I should be able to make the mirror update itself from the repository on the daddy github. 在转换期间,我应该能够从daddy github上的存储库中更新镜像。 (Or will I? I haven't found a command in the UI to do an update.) (或者我会吗?我没有在UI中找到执行更新的命令。)

Then I will delete the "authoritative" github repository, and the mirror will become authoritative. 然后我将删除“权威”github存储库,镜像将变得具有权威性。

But how does that happen? 但是这是怎么发生的? Does each developer need to change the url for "origin" in .git/config? 每个开发人员是否需要更改.git / config中“origin”的url?

Will the mirror accept pushes that aren't updates from its clone-parent? 镜像是否会接受来自其克隆父级的更新?

Your process is almost perfect. 你的过程几近完美。 The only thing was a missing --mirror parameter on the initial clone. 唯一的问题是初始克隆上缺少--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

I would not leave the github repo open for changes, since it would not be clear to everyone in the project which repo is now the correct repo. 我不会让github repo公开进行更改,因为项目中的每个人都不清楚哪个repo现在是正确的回购。 You can still do it, if you run on the server-repo 如果你在server-repo上运行,你仍然可以这样做

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

and then regularly (like in a cron job) 然后定期(比如在cron工作)

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

Edit 编辑

You also can use the local mirror to do the exchange. 您也可以使用本地镜像进行交换。 But there is no easy automated process, since git can't decide neither what to do with deleted branches, nor what to do with diverged branches. 但是没有简单的自动化过程,因为git既不能决定如何处理已删除的分支,也不能决定如何处理分支分支。 Sou you need to keep a working repository where you regular fetch the stuff from the former github-repo, fetch the stuff from the internal repo, resolve diverging history and push this stuff back to the internal repo. 你需要保留一个工作存储库,你可以定期从前github-repo中获取东西,从内部存储库获取东西,解决分歧的历史记录并将这些东西推回内部存储库。

The simplest process would be for the developers to clone the new (private) repo and go on from there. 最简单的过程是开发人员克隆新的(私人)仓库并从那里继续。
If they have any pending changes in progress in their former repo, they can export those as patches and apply them on the new locally cloned repo before pushing them back to the new origin . 如果他们在以前的仓库中有任何待处理的更改,他们可以将这些更改导出为补丁并将其应用于新的本地克隆仓库,然后再将其推回新的origin (See What is the difference between ' git format-patch ' and ' git diff '? and git format-patch man ) (请参阅' git format-patch '和' git diff '之间有什么git diffgit format-patch man

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

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