Michael Crosby

How to manage your website with git

So this is much easier if you have a static site that is generated using pelican or jerkyll. Both of these apps are great for generating blogs out of markdown or other simple text markup language. I use pelican because it is built with python and that is what I develop in.


So on your local machine you will need your basic folder structure setup and if you are not already using git to manage your files, now is the time to start. In terminal cd into your site dir and:

git init

This is create the local git repo that you need. Go ahead and commit the files that you already have done and now we can work on the server.


Make sure that you have ssh access to your web server. The first thing you need to do is cd into your users main directory, not your www or directory that hosts the files that are displayed to your users and we will make a new directory:

mkdir cmsite.git
cd cmsite.git
git init --bare

This will create a bare git repo that will accept the files when you do a push to it. Now we will need to setup a hook that will checkout the latest push into the actual directory that hosts our content. So now we need to add the hook the the hooks directory in cmsite.git in my case.

vim hooks/post-receive
GIT_WORK_TREE=/home/crosbymichael/crosbymichael.com git checkout -f

Make sure that this file is executable so do a quick:

chmod 755 hooks/post-receive

Final Steps

Now we just need to setup our new remote repo on our local machine. So cd into your local git repo and type:

git remote add website ssh://username@yoursite.com/~/cmsite.git

Now all your have to do is push to production when you need to update your site and git does all the rest.

git push website master

Because you can have more than one remote in git, you could have a test site and your production site, and another offsite repo for backups. You can run tests on your test site and then when everything is good to go you just push to production.

comments powered by Disqus