Gitlab存储库镜像 [英] Gitlab repository mirroring

查看:223
本文介绍了Gitlab存储库镜像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将 gitlab 设置为自动同步(镜像)托管在其他位置的存储库?



目前,我所知道的最简单的方法是手动推送到两个(gitlab和另一个)存储库,但这很耗时且容易出错。



最大的问题是镜像可以重新同步,两个用户同时将更改推送到两个不同的存储库。我可以想到的最好的方法来防止这个问题,以确保用户只能推送到其中一个存储库。

解决方案

2016年12月更新:Mirroring支持GitLAb EE 8.2+:请参阅存储库镜像



正如晓东奇所述: p>


这个答案可以在不使用任何命令行的情况下简化(只需在Gitlab repo管理界面上设置它)







原始答案(2013年1月)

repo是 bare repo ,那么您可以添加一个post-receive hook到你的gitlab管理的仓库,并推送到你的远程仓库中。

 #!/ bin / bas h 
git push --mirror slave_user@mirror.host:/path/to/repo.git



作为Gitolite(由Gitlab使用)提及


如果您只想在几个特定的​​存储库中安装钩子,请直接在服务器上执行。




这将在:

 〜git / repositories / yourRepo.git / hook / post-receive 






提醒(更新Ocotober 2014 )



Ciro Santilli 指出在评论中:


今天(2014年第四季度)这将失败,因为GitLab会自动将github.com/gitlabhq/gitlab-shell/tree/...插入到前夕ry存储库管理。

因此,如果您进行此更改,您修改的每个存储库都会尝试推送。

更新时不必提及可能的冲突 gitlab- shell ,并且当前脚本是一个ruby脚本,而不是bash(并且你不应该删除它!)。



您可以通过阅读当前目录名称并确保它与远程服务器之间的双向注入来解决此问题,但我建议人们远离这些东西。


查看(并为之投票) feeadback推送到GitLab Repo后自动推送到远程镜像仓库




2016年7月更新:我看到为GitLab EE(企业版)添加了这种功能: MR 249




  • 添加在Mirror Repository设置下输入远程推送URL的功能

  • 添加实施代码以推送至远程存储库
  • 添加新的后台工作者

  • 显示最新的更新日期和同步错误
  • 每小时同步远程镜像。
  • c $ c> Remote Mirror Repository ( issues 17940 )可能会非常棘手:


    我目前正试图转移我公司Lossless GmbH的开源npm模块的主要开发( https://www.npmjs.com/~lossless )从GitHub.com到GitLab。 com



    我从GitHub导入所有的回购站,但是当我尝试关闭 Mirror Repository 并切换在远程镜像存储库上使用原始GitHub URL时出现错误消息:




    远程镜像url已被使用

    这是一个回购这个失败: https://gitlab.com/pushrocks/npmts
    编辑2个月前



    转它只是需要多个步骤:
    $ b


    • 禁用镜像库

    • 按下save
    • >
    • 删除URl

    • 按下保存

    • 然后添加远程镜像
    • ul>


    Is it possible to have gitlab setup to automatically sync (mirror) a repository hosted at another location?

    At the moment, the easiest way I know of doing this involves manually pushing to the two (gitlab and the other) repository, but this is time consuming and error prone.

    The greatest problem is that a mirror can resynchronize is two users concurrently push changes to the two different repositories. The best method I can come up with to prevent this issue is to ensure users can only push to one of the repositories.

    解决方案

    Update Dec 2016: Mirroring is suported with GitLAb EE 8.2+: see "Repository mirroring".

    As commented by Xiaodong Qi:

    This answer can be simplified without using any command lines (just set it up on Gitlab repo management interface)


    Original answer (January 2013)

    If your remote mirror repo is a bare repo, then you can add a post-receive hook to your gitlab-managed repo, and push to your remote repo in it.

    #!/bin/bash
    git push --mirror slave_user@mirror.host:/path/to/repo.git
    

    As Gitolite (used by Gitlab) mentions:

    if you want to install a hook in only a few specific repositories, do it directly on the server.

    which would be in:

    ~git/repositories/yourRepo.git/hook/post-receive
    


    Caveat (Update Ocotober 2014)

    Ciro Santilli points out in the comments:

    Today (Q4 2014) this will fail because GitLab automatically symlinks github.com/gitlabhq/gitlab-shell/tree/… into every repository it manages.
    So if you make this change, every repository you modify will try to push.
    Not to mention possible conflicts when upgrading gitlab-shell, and that the current script is a ruby script, not bash (and you should not remove it!).

    You could correct this by reading the current directory name and ensuring bijection between that and the remote, but I recommend people to stay far far away from those things

    See (and vote for) feeadback "Automatic push to remote mirror repo after push to GitLab Repo".


    Update July 2016: I see this kind of feature added for GitLab EE (Enterprise Edition): MR 249

    • Add ability to enter remote push URL under Mirror Repository settings
    • Add implementation code to push to remote repository
    • Add new background worker
    • Show latest update date and sync errors if they exists.
    • Sync remote mirror every hour.

    Note that the recent Remote Mirror Repository (issues 17940) can be tricky:

    I'm currently trying to shift main development of the Open Source npm modules of my company Lossless GmbH (https://www.npmjs.com/~lossless) from GitHub.com to GitLab.com

    I'm importing all the repos from GitHub, however when I try to switch off Mirror Repository and switch on Remote Mirror Repository with the original GitHub URL I get an error saying:

    Remote mirrors url is already in use
    

    Here is one of the repos this fails with: https://gitlab.com/pushrocks/npmts Edited 2 months ago

    turns out, it just requires multiple steps:

    • disable the Mirror Repository
    • press save
    • remove the URl
    • press save
    • then add the Remote Mirror

    这篇关于Gitlab存储库镜像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆