2012-04-27 140 views
6

我的任务是将我们的存储库从公共github移动到我们本地网络上的github私有实例。从Github转移“权威”git存储库到私人github

我的想法是将它们与

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

在移动过程中的过渡时间,我应该能够做镜像更新自己从爸爸GitHub上的仓库。 (或者我会吗?我还没有在UI中发现一条命令来进行更新。)

然后我将删除“权威”的github存储库,镜像将变得权威。

但这是如何发生的?每个开发者是否需要在.git/config中更改“origin”的url?

镜像是否接受不是来自其克隆父亲的更新?

+0

更多信息:“local-github-url”确实是一个Github。这是一个私人Github企业服务。我没有shell或crontab访问私人Github。 – Mojo 2012-04-27 21:09:22

回答

5

你的过程几乎完美。唯一的原因是初始克隆中缺少--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库开放的变化,因为它不会是每个人都清楚的项目,该项目回购现在是正确的回购。你仍然可以做到这一点,如果你在服务器回购

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获取东西,从内部仓库获取东西,解决分歧历史,并将这些东西推回到内部仓库。

+1

Rudi,很好的回答!然而,它假定私人回购是在我有shell/crontab的机器上。在我的情况下,私人回购是在防火墙内的“Github Enterprise”实例。除了通过git和网站之外,我没有直接访问私有存储库的权限。 – Mojo 2012-04-27 21:06:27

+0

我还没有看到GHE的解决方案。甚至在GHE网站上的一些讨论也被删除了。 – Shane 2015-01-02 18:25:34