假如你在本地的虚拟机或者公司内网服务器部署了gitlab,但愿版本控制管理本地化或内网化,那如何实现版本控制管理本地化或内网化的同时,可以将项目基于版本控制管理部署在线上服务器,这就是如下要讨论的问题。html
上面方案存在的关卡git
远程服务器如何同步或克隆本地gitlab的代码服务器
gitlab如何项目实现自动化同步部署远程服务器markdown
在gitlab创建项目(即在gitlab创建仓库过程)app
在远程服务器创建裸仓库ssh
本地克隆gitlab仓库ide
ssh-keygen -t rsa -C "your_email@example.com"
在gitlab部署本地ssh-keygitlab
第一步:post
第二步:测试
host test hostname 0.0.0.0 #你的主机地址 user root port 22 identityfile ~/.keys/test #你的私钥地址
#!/bin/sh # example hook script for the "post-receive" event. # # The "post-receive" script is run after receive-pack has accepted a pack # and the repository has been updated. It is passed arguments in through # stdin in the form # <oldrev> <newrev> <refname> # For example: # aa453216d1b3e49e7f6f98441fa56946ddcd6a20 68f7abf4e6f922807889f52bc043ecd31b79f814 refs/heads/master # # see contrib/hooks/ for a sample, or uncomment the next line and # rename the file to "post-receive". #. /usr/share/git-core/contrib/hooks/post-receive-email while read oldrev newrev ref do branch=$(git rev-parse --symbolic --abbrev-ref $ref) if [ "$branch" = "1.0" ] then git push -f test:/var/www/html/test.git $branch fi done
#!/bin/sh # # An example hook script for the "post-receive" event. # # The "post-receive" script is run after receive-pack has accepted a pack # and the repository has been updated. It is passed arguments in through # stdin in the form # <oldrev> <newrev> <refname> # For example: # aa453216d1b3e49e7f6f98441fa56946ddcd6a20 68f7abf4e6f922807889f52bc043ecd31b79f814 refs/heads/master # # see contrib/hooks/ for a sample, or uncomment the next line and # rename the file to "post-receive". #. /usr/share/git-core/contrib/hooks/post-receive-email while read oldrev newrev ref do if [[ $ref =~ .*/1.0$ ]]; then echo "1.0 ref received. Deploying 1.0 branch to test server..." git --work-tree=/var/www/html/test--git-dir=$GIT_DIR checkout -f $ref fi done
注意:
(1)出现下面
缘由:gitlab未把host添加进kown_hosts