Skip to content

How to set up Git Hooks

Daisho Komiyama edited this page Jan 20, 2018 · 15 revisions

This is a note about what I've done for setting up Git Hooks. The website is daishodesign.com. domain is already taken and setup. How to create a server block

Create a directory

Create site-daishodesign.git under /var/repo/

Initiate Git

Initiate Git with bare flag git init --bare The commande above should have created the directory hooks/. Navigate into it.

Create post-receive file

Create it under hooks/ sudo nano post-receive

Edit post-receive file

Open it with nano then add this line. #!/bin/sh git --work-tree=/var/www/daishodesign.com/html --git-dir=/var/repo/site-daishodesign.git checkout -f

Create symbolic link

Create symlink from server block file to a directory sites-enabled sudo ln -s /etc/nginx/sites-available/daishodesign.com /etc/nginx/sites-enabled/

Give permissions

Give execution permissions to post-receive file sudo chmod +x post-receive

Add production remote to local git

Go back to local and navigate to the root directory of your site to add a production remote git remote add production ssh://root@daishodesign.com/var/repo/site-daishodesign.git

That's it.

You can push your commits with git push origin master to your Github repo and you can also push all your changes to production with git push production master It's super fast compared to sending all files using a FTP software. Not only it's faster but also safer because you can't miss files that you changed.

Clone this wiki locally