Skip to main content

Simple git deployment for small sites

Use FTP only for media files and settings ... but deploy very fast with git:

Requirements:

  • Ssh user with access to directory outside document root

  • Git installed

  • Ssh Access with ssh-keygen

  • Choose document root for domain in configuration


 

On remote server:

Ssh into it

$ mkdir NAMEOFSITE.git && cd NAMEOFSITE.git

$ git init --bare

$ cd ..

$ mkdir /path/to/document_root

$ cd NAMEOFSITE.git/hooks

$ cp post-receive.sample post-receive

$ vim post-receive

 

… in file post receive add the following line:

GIT_WORK_TREE=/path/to/document_root git checkout -f

Save file with vim and make it executable

$ chmod 0700 post-receive

 

On local machine (development environment):

Add a second remote (live in my example ) to your repo:

$ git remote add live ssh://user@server.example.org/absolute/path/to/NAMEOFSITE.git && git push live +master:refs/heads/master

 

Daily workflow:

To push to liveserver simply do a

$ git push live master

 

To force a copy, when everything seems up-to-date, ssh into the server and do

$ sh NAMEOFSITE.git/hooks/post-receive