方法一、
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、
??
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。