MysticCodes MysticCodes -4 years ago 147
Git Question

Git post-receive hooks

I have two different servers. One is for repository and another one for web application.
I'm trying to setup post-receive hook. When I push code into repository server then I want project codes to be in application server.

Server

$ mkdir /home/yo/repo.git
$ cd /home/yo/repo.git
$ git init --bare
$ cd /hooks
$ touch post-receive.sh
$ chmod +x post-receive.sh


post-receive.sh

#!/bin/bash
while read oldrev newrev ref
do
git --work-tree=appuser@appserver:/var/www/multiverse --git-dir=/home/yo/repo.git checkout -f
done


Local

$ cd /home/Sites/multiverse
$ git init
$ git remote add origin repouser@reposerver:/home/yo/repot.git
$ git add .
$ git commit -am "initial commit"
$ git push origin master


How can I achieve this using post-receive?

Answer Source

The post-receive script must be installed inside the hooks directory of the bare git (/home/yo/repo.git/hooks) and must be named post-receive without any extension.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download