MysticCodes
MysticCodes

Reputation: 3282

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?

Upvotes: 0

Views: 1469

Answers (1)

onekiloparsec
onekiloparsec

Reputation: 2063

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.

Upvotes: 2

Related Questions