Using git to deploy new versions

Simple instructions for setting up git so that you can push new versions to server from the comfort of your workstation. This is based on article by Abhijit Menon-Sen. If you need more details, take a look at that.

This will create the home directory for the project underneath /var. Git repository shall be put on the same place, in .git subfolder. If you are using this to push a website, you need to either move the .git folder to some other place or use .htaccess to make sure the .git folder is not exposed to world.

On server (replace your project name on the first line)

mkdir /var/$PROJECT
mkdir /var/$PROJECT/.git
git init --bare /var/$PROJECT/.git
cat <<EOF > /var/$PROJECT/.git/hooks/post-receive
GIT_WORK_TREE=/var/$PROJECT git checkout -f

chmod +x /var/$PROJECT/.git/hooks/post-receive

On client, where you have the git repository run the following to configure:

git remote add live ssh://<username>@<myserver>:/var/<project>

Then use this to push the master to the server

git push live master