简体   繁体   English

如何将git存储库从github移动到运行gitolite的本地服务器

[英]How to move git repositories from github to local server running gitolite

I would like to know the preferable way to move all my git repositories currently hosted on github to a new git server gitolite-based. 我想知道将目前托管在github上的所有git存储库移动到基于gitolite的新git服务器的更好方法。

Just for knowing, the reason why I'm doing this switch is the adoption of Redmine to support our project management process. 仅仅是为了了解,我正在进行此转换的原因是采用Redmine来支持我们的项目管理流程。

Add the new repo in gitolite-admin/conf/gitolite.conf 在gitolite-admin / conf / gitolite.conf中添加新的repo

repo my-new-repo
    RW+            = your-user

Add, commit and push the changes into gitolite-admin 添加,提交并将更改推送到gitolite-admin

git add conf/gitolite.conf
git commit -m "Added my-new-repo"
git push origin

Clone your github repo and checkout all the branches present 克隆你的github repo并检查所有分支

git clone github.com:/USERNAME/YOUR_REPO.git
cd YOUR_REPO
for branch in `git branch -a | grep remotes | grep -v HEAD | grep -v master`; do     git branch --track ${branch##*/} $branch; done

Remove the github remote, and add your gitolite remote: 删除github遥控器,并添加你的gitolite遥控器:

git remote rm origin
git remote add origin YOURSERVER:my-new-repo.git

Push all the refs onto the repo managed by gitolite: 将所有refs推送到由gitolite管理的repo:

git push --all origin

I verified the steps in a test repository of mine, and all the refs seem to have propagated into the new repo. 我验证了我的测试存储库中的步骤,并且所有refs似乎都已传播到新的repo中。

UPDATE: Like Seth pointed out, any other refs other than branches are not propagated to the new repo. 更新:像Seth指出的那样,除了分支之外的任何其他引用都不会传播到新的repo。 I too feel Mirror would be a better option. 我也觉得镜子会是一个更好的选择。

With reference to this: http://gitolite.com/gitolite/basic-admin/#appendix-1-bringing-existing-repos-into-gitolite . 参考这个: http//gitolite.com/gitolite/basic-admin/#appendix-1-bringing-existing-repos-into-gitolite How about: 怎么样:

  1. On the gitolite server, make a mirror of the github repositories with the command git clone --mirror <github git repo path> 在gitolite服务器上,使用命令git clone --mirror <github git repo path> github存储库的镜像
  2. Move the mirror repo to the correct location as in the link above, then just follow the section moving existing repos into gitolite of the guide? 将镜像回购移动到上面链接中的正确位置,然后按照将现有回购移动到指南的gitolite的部分进行操作?

The best thing I can think of would be to pull a local copy, change the origin to the new server, and then push: 我能想到的最好的事情是拉一个本地副本,将原点更改为新服务器,然后推送:

git pull --all
git remote rm origin
git remote add origin <new repo address>
git push --all --repo=origin

Perhaps you also want to bring your tags to the new server. 也许您还想将标签带到新服务器。 This can be done by 这可以通过

    git push --tags

To mirror a GitHub repo onto Gitolite, first create a new repo on Gitolite (using the gitolite-admin repo - I'll assume the Gitolite admin knows how to do that), but here's an example config entry: 要将GitHub仓库镜像到Gitolite,首先在Gitolite上创建一个新的仓库(使用gitolite-admin仓库 - 我假设Gitolite管理员知道如何做到这一点),但这是一个示例配置条目:

repo github/<gh-user>/<gh-repo>
desc = "Repository description [https://github.com/<gh-user>/<gh-repo>]"
owner = "My Name"
category = "GitHub"
RW+ = my_key

where <gh-user> is the GitHub user and <gh-repo> is the GitHub repository being mirrored. 其中<gh-user>是GitHub用户, <gh-repo>是镜像的GitHub存储库。 This example places the mirror within a GitHub and user subdirectory, but you can use any repo path that suits. 此示例将镜像放在GitHub和user子目录中,但您可以使用任何适合的repo路径。

Then, from anywhere with access to both GitHub and Gitolite: 然后,从任何可以访问GitHub和Gitolite的地方:

$ git clone --mirror https://github.com/<gh-user>/<gh-repo>
$ cd <gh-repo>.git
$ git push --mirror gitolite git@git:github/<gh-user>/<gh-repo>
$ cd ..
$ rm -rf <gh-repo>.git

where git@git is the SSH user and hostname used to connect to Gitolite. 其中git@git是用于连接Gitolite的SSH用户和主机名。 The local clone is temporary and is deleted afterwards. 本地克隆是临时的,之后会被删除。

The OP asked only about moving repositories, in which case he might stop here. OP只询问移动存储库,在这种情况下,他可能会停在这里。 However, should it be desirable to host a local mirror of a repo on GitHub and periodically synchronize the local mirror then here's a way to do that. 但是,如果需要在GitHub上托管repo的本地镜像并定期同步本地镜像,那么这是一种方法。

To sync the Gitolite mirror with GitHub, log on to the Gitolite server as the Gitolite admin ( git ) user and perfom the following configuration: 要将Gitolite镜像与GitHub同步,请以Gitolite admin( git )用户身份登录Gitolite服务器并执行以下配置:

$ cd ~git/repositories/github/<gh-user>/<gh-repo>
$ git remote add origin https://github.com/<gh-user>/<gh-repo>
$ git config remote.origin.fetch "+*:*"

The parameters in the commands are explained clearly here . 这里将清楚地解释命令中的参数。

Then, to sync the repo: 然后,同步回购:

$ git fetch --prune

The fetch could be automated via a cron job. 可以通过cron作业自动获取。

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

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