如何创建一个 Gitlab webhook 来更新 Github 上的镜像仓库? [英] How to create a Gitlab webhook to update a mirror repo on Github?

查看:22
本文介绍了如何创建一个 Gitlab webhook 来更新 Github 上的镜像仓库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 Gitlab 中创建一个 webhook,以便在发生 push 事件时自动更新 Github 上的镜像存储库.我检查了这个 如果你需要帮助.

完成后,您只需配置 git 服务器和 github 之间的连接:为 git 用户的 ssh 配置添加别名(将以下行添加到 /home/git/.ssh/config - 如果不存在则创建它)

主机reponame身份文件/home/git/.ssh/reponame_key主机名 github.com用户 git

现在将新的远程(使用您刚刚创建的别名)添加到您的存储库:

cd/home/git/repositories/namespace/reponame.gitgit remote add --mirror github reponame:youruser/reponame.git

现在一切就绪,您必须创建实际的钩子:

cd/home/git/repositories/namespace/reponame.git/hooksecho "exec git push --quiet github &">>接收后chmod 755 接收后

最后一条命令非常重要,因为 git 会在运行之前检查钩子是否可执行.

就是这样!

(根据你的真实账户替换reponame、namespace和youruser并享受).

最后一点:如果您希望您的姓名和头像靠近 github 上的提交,请确保您在 gitlab 上使用的电子邮件地址也是与您的 github 帐户相关的地址之一.否则你会看到你的 gitlab 用户名.

I would like to create a webhook within Gitlab to automatically update a mirror repository on Github, whenever a push event happens. I've checked this page, but I didn't understand how it is done.

My Gitlab version is 6.5. Here is the configuration page:

What should I put in URL? Where do I need to place the script to update the repository?

解决方案

You don't need a webhook for that. A regular post-receive hook will work very well.

To create and use such a hook you just have to login on the server where your gitlab is installed and create an ssh key for git user.

sudo -u git ssh-keygen -f /home/git/.ssh/reponame_key

(do not type any passphrase when prompted)

Go to your github account and add the public key (it's been created as /home/git/ssh/reponame_key.pub) to your project as a deploy key. have a look at https://help.github.com/articles/managing-deploy-keys if you need help with that.

Once that is done, you just have to configure the connection between your git server and github's: add an alias to git user's ssh configuration (add following lines to /home/git/.ssh/config - create it if it's not present)

Host reponame  
IdentityFile /home/git/.ssh/reponame_key  
HostName github.com  
User git 

Now add the new remote (using the alias you just created) to your repository:

cd /home/git/repositories/namespace/reponame.git

git remote add --mirror github reponame:youruser/reponame.git

Now that everything is in place you'll have to create the actual hook:

cd /home/git/repositories/namespace/reponame.git/hooks

echo "exec git push --quiet github &" >> post-receive

chmod 755 post-receive

The lastcommand is very important because git will check if a hook is executable before running it.

That's it!

(Replace reponame, namespace and youruser according to your real accounts and enjoy).

Last note: if you want your name andavatar near commits on github, make sure that the email address you are using on gitlab is one of the addresses inked to your github account as well. You'll see your gitlab username otherwise.

这篇关于如何创建一个 Gitlab webhook 来更新 Github 上的镜像仓库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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