- 在linux安装git, 新建一个git用户
- 新建一个git仓库
$ su git
$ cd /home/git/gitrepo
$ git init --bare frontcenter.git
- 在本地克隆该仓库
$ git clone git@服务器地址:/home/git/gitrepo/frontcenter.git
- 如果希望将本地仓库关联到该远程仓库,执行以下命令
$ git remote add origin git@服务器地址:/home/git/gitrepo/frontcenter.git
- 在hooks里面增加 post-receive 钩子,本地提交代码之后自动部署到服务器
$ cd /home/git/gitrepo/frontcenter.git/hooks/
$ touch post-receive
$ chmod 777 post-receive
$ vi post-receive
- 增加post-receive如下
#!/bin/bash
export GIT_WORK_TREE=/home/git/workSpace/frontcenter(远程项目地址)
export GIT_DIR=${GIT_WORK_TREE}/.git
cd ${GIT_WORK_TREE}
git pull origin
- 在服务端workSpace下拉取仓库代码,
$ cd /home/git/workSpace
$ git clone git@服务器地址:/home/git/gitrepo/frontcenter.git
- 本地改完内容提交
$ git add .
$ git commit 'test'
$ git push
- 观察服务器/home/git/workSpace, 发现内容已更新