Consider the following situation:
I have a git repository foo.git that contains code of a javascript project. In this repository there is a branch production that contains the state of the code as served by a web-server which fetches the code from /var/www/foo. This repository is the master repository for the project. Everybody pushes and pulls from/to it.
Is it possible to have /var/www/foo updated to a checkout of production whenever someobody pushes to that particular branch? You may assume that the git daemon (or the user git which is the user all people log in to to connect via SSH) is entitled to write to said directory.
You have to create a bare repository on the server with
git init --bare.Then use a
post-receivehook to trigger your deploy.How you deploy is up to you.
My Deployment Strategy
I usually place a
deploydirector, somewhere logical.Then each checkout, I unpack the latest branch to
deploy/COMMIT_IDwhereCOMMIT_IDis the hash of the latest push. Once the checkout is complete, you can re-point a symlink to the latest deployment directory.My usual directory structure:
Unpacking the Update
Rather than use a
git-checkout, I usually usegit-archiveto unpack a branch into a directory.Your web-server can point to
deploy/latest, updates will be more-or-less atomic.I use this often in production, and has a few benefits over unpacking over the same directory.
Tips