进入git服务端仓库钩子目录 /home/git/repositories/blog/.git/hooks cp post-receive.sample post-receive vi post-receive 内容为: #!/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 ## 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". unset GIT_INDEX_FILE git --work-tree=/usr/share/nginx/html/blog checkout -f 保存 这时注意看钩子 post-receive的属主和权限,因为我是用root用户复制的,要改回git用户所有 chown git:git post-receive ll 查看权限如下,要注意要有执行权限 -rwx--x--x 1 git git 672 Dec 29 22:36 post-receive 测试发现不行,看了别的文章猜想是代码目录权限问题 代码目录 blog是nginx所有,将git用户加入nginx用户组里 usermod -a -G nginx git 再push代码,发现服务端有反应了 Total 6 (delta 3), reused 0 (delta 0) remote: error: unable to unlink old 'backend/views/wechatUser/_form.php' (Permis sion denied) remote: error: unable to unlink old 'backend/views/wechatUser/_search.php' (Perm ission denied) remote: error: unable to unlink old 'backend/views/wechatUser/create.php' (Permi ssion denied) remote: error: unable to unlink old 'backend/views/wechatUser/index.php' (Permis sion denied) remote: error: unable to unlink old 'backend/views/wechatUser/update.php' (Permi ssion denied) remote: error: unable to unlink old 'backend/views/wechatUser/view.php' (Permiss 还是权限, 又把这些文件属主改为nginx,再push,就可以了 参考 https://www.digitalocean.com/community/tutorials/how-to-use-git-hooks-to-automate-development-and-deployment-tasks