初次镜像远端仓库
1 |
git clone --mirror git://remote-repository-url |
进入到项目中
1 |
cd xx.git |
当客户端push到服务器来时,自动更新某个文件夹。
1 |
mkdir /var/www/ #网站的目录地址 |
2 |
vi hooks/post-receive #新建文件,输入以下内容 |
1 |
#!/bin/sh |
2 |
GIT_WORK_TREE=/var/www/ git checkout -f |
1 |
chmod +x hooks/post-receive #添加可执行权限 |
post-receive这个脚本在提交文件到git仓库时,会运行文件内的代码,所以通过这样的方法,我们在客户端push提交代码后,就能自动更新网站的文件了。
执行
更新仓库
1 |
git remote update |