远端机器

$ mkdir /www/teacherapi  # 创建工作目录

$ cd /data/git

$ git init teacherapi.git --bare --shared

Initialized empty shared Git repository in /data/git/teacherapi.git/

$ cd teacherapi.git/

$ vi hooks/post-receive # 或者使用 $ cat > hooks/post-receive 创建并键入如下代码,最后ctrl+d保存退出,

#!/bin/sh

GIT_WORK_TREE=/www/teacherapi git checkout -f <branch>  # 默认master分支

$ chmod +x hooks/post-receive  # 设置可执行权限

也可以用下面代码片段

$ cd git

$ mkdir somesite.git

$ cd somesite.git/

$ git init --bare

Initialized empty Git repository in /home/caius/git/somesite.git/

$ git --bare update-server-info

$ git config core.worktree /home/caius/vhosts/somesite.com/htdocs

$ git config core.bare false

$ git config receive.denycurrentbranch ignore

$ cat > hooks/post-receive

#!/bin/sh

git checkout -f

^D

$ chmod +x hooks/post-receive

工作树更新完成后执行脚本

$ cd /gitpah/hooks/

$ vi post-checkout  #创建post-checkout键入如下代码,当'git-checkout'命令更新完整个工作树(worktree)后,这个钩子就会被调用

#!/bin/sh

/etc/init.d/teacherapitest.tbkt.cn restart

$ chmod +x post-checkout

本地机器

$ git clone ssh://root@192.168.0.106:6022/data/git/teacherapi.git

$ cd teacherapi/

$ echo 'Hello, world!' > index.html

$ git add index.html

$ git commit -m "init project"

$ git push origin master:master

添加远程仓库

$ git remote add 106 ssh://root@192.168.0.106:6022/opt/gitdata/chsy_cms.git

远程推送过程中报错:cannot run hooks/post-receive: No such file or directory

除了检查post-receive文件内容外,还要看看文件格式对不对,使用$ cat -A hook/post-receive 查看

文档内容参考:

http://caiustheory.com/automatically-deploying-website-from-remote-git-repository

http://toroid.org/ams/git-website-howto

更多钩子用法:http://www.360doc.com/content/12/1012/11/10140166_241004726.shtml

最新文章

  1. 如何利用excel中的数据源制作数据地图
  2. STM32命名原则
  3. JAVASCRIPT 中 FOR (VAR I IN DATA) 循环数组项
  4. 基于RulesEngine的业务规则实现
  5. ffmepg-nginx-nginx-rtmp-module配置脚本
  6. Laravel教程 一:安装及环境配置
  7. Oracle 11g 客户端 下载地址
  8. eclipse下使用maven配置库托管jar包
  9. cssText设置css样式
  10. Oracle 11g-R2 SQL Developer连接MSSQL2008
  11. Android开发报错系列(一),java.lang.NullPointerException,at android.widget.ListView.setupChild
  12. iOS发展 - 使用您自己的自定义字体
  13. SQL点滴3—一个简单的字符串分割函数
  14. DirectFB学习笔记二
  15. SVN 、Git、Github的使用
  16. ubuntu17 安装中文输入法
  17. IEnumerable、IEnumerator、ICollection、IList、List的继承关系及简单使用
  18. linux 7 关闭防火墙 开启sshd服务
  19. 将 ASP.NET Core 2.0 项目升级至 ASP.NET Core 2.1.3X
  20. Hadoop记录-hadoop集群常见问题汇总

热门文章

  1. Android学习笔记——文件路径(/mnt/sdcard/...)、Uri(content://media/external/...)学习
  2. php 练习
  3. JUC回顾之-volatile的原理和使用
  4. WIN7里为什么没有TELNET,怎么添加
  5. [原]AppPoolService-IIS应用程序池辅助类(C#控制应用程序池操作)
  6. Windows环境下Sybase12.5 图文安装教程
  7. sybase常用SQL语句,工作中积累的
  8. mysql封装类
  9. eclipse 中的 jar file 和 runnable jar file的区别
  10. Java程序员最常用的8个Java日志框架