git Gitlab 仓库镜像
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14288288/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Gitlab repository mirroring
提问by goncalopp
Is it possible to have gitlabset up to automatically sync (mirror) a repository hosted at another location?
是否可以将gitlab设置为自动同步(镜像)托管在另一个位置的存储库?
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.
目前,我所知道的最简单的方法是手动推送到两个(gitlab 和另一个)存储库,但这既耗时又容易出错。
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.
最大的问题是一个镜像可以重新同步是两个用户同时将更改推送到两个不同的存储库。我能想出的防止此问题的最佳方法是确保用户只能推送到其中一个存储库。
采纳答案by VonC
Update Dec 2016: Mirroring is suported with GitLAb EE 8.2+: see "Repository mirroring".
2016 年 12 月更新:GitLab EE 8.2+ 支持镜像:请参阅“存储库镜像”。
As commented by Xiaodong Qi:
正如评论说晓东齐:
This answer can be simplified without using any command lines (just set it up on Gitlab repo management interface)
无需使用任何命令行即可简化此答案(只需在 Gitlab 存储库管理界面上设置即可)
Original answer (January 2013)
原始答案(2013 年 1 月)
If your remote mirror repo is a barerepo, then you can add a post-receive hook to your gitlab-managed repo, and push to your remote repo in it.
如果你的远程镜像仓库是一个裸仓库,那么你可以在你的 gitlab 管理的仓库中添加一个 post-receive 钩子,然后推送到你的远程仓库。
#!/bin/bash
git push --mirror [email protected]:/path/to/repo.git
As Gitolite (used by Gitlab) mentions:
正如 Gitolite(由 Gitlab 使用)提到的:
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)
警告(2014 年 10 月更新)
fxscpoints out in the comments:
Today (Q4 2014) this will failbecause 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 upgradinggitlab-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
今天(2014 年第四季度)这将失败,因为 GitLab 自动将github.com/gitlabhq/gitlab-shell/tree/... 符号链接到它管理的每个存储库中。
因此,如果您进行此更改,您修改的每个存储库都会尝试推送。
更不用说升级时可能发生的冲突gitlab-shell
,当前脚本是 ruby 脚本,而不是 bash(你不应该删除它!)。您可以通过读取当前目录名称并确保它与远程目录之间的双射来纠正此问题,但我建议人们远离这些东西
See (and vote for) feeadback "Automatic push to remote mirror repo after push to GitLab Repo".
查看(并投票)反馈“推送到 GitLab 存储库后自动推送到远程镜像存储库”。
Update July 2016: I see this kind of feature added for GitLab EE (Enterprise Edition): MR 249
2016 年 7 月更新:我看到为 GitLab EE(企业版)添加了这种功能: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.
- 添加在镜像存储库设置下输入远程推送 URL 的功能
- 添加实现代码推送到远程仓库
- 添加新的后台工作者
- 显示最新更新日期和同步错误(如果存在)。
- 每小时同步一次远程镜像。
Note that the recent Remote Mirror Repository
(issues 17940) can be tricky:
请注意,最近Remote Mirror Repository
(issues 17940)可能很棘手:
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 onRemote Mirror Repository
with the original GitHub URL I get an error saying:
我目前正在尝试将我公司 Lossless GmbH(https://www.npmjs.com/~lossless)的开源 npm 模块的主要开发从 GitHub.com 转移到 GitLab.com
我正在从 GitHub 导入所有存储库,但是当我尝试关闭
Mirror Repository
并Remote Mirror Repository
使用原始 GitHub URL打开时,我收到一条错误消息:
Remote mirrors url is already in use
Here is one of the repos this fails with: https://gitlab.com/pushrocks/npmtsEdited 2 months ago
这是失败的存储库之一:https://gitlab.com/pushrocks/npmts 2个月前编辑
turns out, it just requires multiple steps:
- disable the Mirror Repository
- press save
- remove the URl
- press save
- then add the Remote Mirror
事实证明,它只需要多个步骤:
- 禁用镜像存储库
- 按保存
- 删除 URL
- 按保存
- 然后添加远程镜像
回答by mlncn
If not hosting your own GitLab, it's worth knowing GitLab.com has introduced this feature directly, without any workarounds.
如果不托管您自己的 GitLab,值得知道 GitLab.com 直接引入了此功能,没有任何解决方法。
- From within a project use the gear icon to select Mirror Repository
- Scroll down to Push to a remote repository
- Checkmark Remote mirror repository: Automatically update the remote mirror's branches, tags, and commits from this repository every hour.
- Enter the repository you want to update; for GitHub at least you can include your username and password in the URL, like so:
https://yourgithubusername:[email protected]/agaric/guts_discuss_resource.git
- 从项目中使用齿轮图标选择镜像存储库
- 向下滚动到推送到远程存储库
- 勾选远程镜像仓库:每小时自动从这个仓库更新远程镜像的分支、标签和提交。
- 输入要更新的仓库;对于 GitHub,至少您可以在 URL 中包含您的用户名和密码,如下所示:
https://yourgithubusername:[email protected]/agaric/guts_discuss_resource.git
Note that if you are pulling from a remote repository, it will still push on to the remote repository set here. I haven't tried it, but you should be able to push to and pull from the same repository.
请注意,如果您从远程存储库中拉取,它仍将推送到此处设置的远程存储库。我还没有尝试过,但是您应该能够从同一个存储库推送和拉取。
回答by Breith
A quick summary of configure mirroring repositorieswith GitLab and GitHub
使用 GitLab 和 GitHub配置镜像存储库的快速摘要
- GitHub: Settings > Developer settings > Personal access tokens
- You need enable:
public_repo
- You need enable:
- GitLab: GitLab project > Settings > Repository > Mirroring repositories
Push
推
- Git repository URL:
https://[email protected]/username/repo.git
- Mirror direction:
Push
- Authentication method:
Password
- Password:
your_github_token
- Password:
- Git 存储库网址:
https://[email protected]/username/repo.git
- 镜像方向:
Push
- 认证方式:
Password
- 密码:
your_github_token
- 密码:
Pull
拉
- Git repository URL:
https://github.com/username/repo.git
- Mirror direction:
Pull
- Authentication method:
leave_empty
- Git 存储库网址:
https://github.com/username/repo.git
- 镜像方向:
Pull
- 认证方式:
leave_empty
回答by Sam Gleske
I also created a project to mirror repositories in GitLab 6 through the API (API mostly used on project creation only).
我还创建了一个项目来通过 API 镜像 GitLab 6 中的存储库(API 主要仅用于项目创建)。
回答by William Seiti Mizuta
You can use hooks to customize a script that runs after some commit. With that you can send the new changes to another repository. Look for more information about hook in the following page: http://git-scm.com/book/en/Customizing-Git-Git-Hooks
您可以使用钩子自定义在某些提交后运行的脚本。有了它,您可以将新更改发送到另一个存储库。在以下页面中查找有关钩子的更多信息:http: //git-scm.com/book/en/Customizing-Git-Git-Hooks
回答by Scott Willeke
GitLab Enterprise Edition now supports repository mirroring as of version 8.2. Information about how to configure this is in the Repository Mirroring help topic.
从 8.2 版开始,GitLab 企业版现在支持存储库镜像。有关如何配置它的信息在存储库镜像帮助主题中。
回答by KouiK
The best option is not to use post-receive hooks, but deployments commands that perform synchronisation via rsync, using Capistranoif you like Ruby, using Shipitif you prefer Javascript (Grunt).
最好的选择不是使用 post-receive 钩子,而是通过 rsync 执行同步的部署命令,如果你喜欢 Ruby,使用Capistrano,如果你喜欢 Javascript (Grunt) ,使用Shipit。