方法一、
1、先在服务器创建裸仓库 git init --bare <repo> 裸仓库是可以被正常 clone
和 push
更新的, 裸仓库不包含工作区,所以并不会存在在裸仓库上直接提交变更的情况
git init --bare test.git
2、配置hooks 钩子
cd test/test.git/hooks/
vi post-receive
#!/bin/sh
git --work-tree=/root/test --git-dir=/root/test/test.git checkout -f #/root/test是代码目录,/root/test/test.git 是裸仓库
3、配置本地git conf
vi conf
[remote "web"]
url = git@git.oschina.net/mytest.git #远程仓库
url = 账号@ip:/root/test/test.git #服务器裸仓库
4、测试
git push web master
方法二、
1、配置码云
配置url和密码 (http://127.0.0.1/git_hooks,密码:123456)
2、配置服务器端
@login.route('/git_hooks', methods=['POST'])
def git_payload():
data = request.get_json()
password = '123456'
if data.get('password', None) == password:
if data.get('hook_name') == "push_hooks":
try:
cmd_output = subprocess.Popen(
[". /home/git_sh.sh"], shell=True)
return jsonify({'msg': str(cmd_output)})
except subprocess.CalledProcessError as error:
return jsonify({'msg': str(error.output)})
else:
return jsonify('invalid hooks')
else:
return jsonify('invalid hash')
3、编辑git_sh.sh脚本
cd /home/backend/www/aw
git pull origin master
4、
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。