If you use a static blog system as me or a static site. You may consider which deployment suits you better, sftp maybe a stable old-school way. Today let’s use git to complete this quest. No, not push-then-pull, you can actually push only :)
Furthermore, via this approach, you have a taste to the world of continuous deployment. :) Let’s do this.
We will take advantage of one feature from git called
hooks. It defines some actions that will be done after some triggers. For instance, you can define some actions right after the
push command. Let’s say you wanna copy a whole folder to different place after the server receive a
push. Such as this, you have a automatic deployment system.
There are three types of hooks in git:
- pre-receive: As the name, the action will be taken as soon as the server receives a
- post-receive: Same as
pre-receivebut will operate on each branch
- update: Will be executed when
And, we will use the
update one :)
The following command is simple, just create a folder named blog.git, then make it a git repository.
Now I assume that you still follow from section one, you should be in the
ls command you will see lots of sample files. But we will create our own, and the type is
i to enter the edit mode. Write down the following:
It is easy to understand, all the files in the
git-dir folderwill be checkouted to
You should change that
/var/www/blog to your own folder which holds all the files of your blog.
And this file should be executable. So we need to change its permission.
chmod +x post-receive
Now, as normal, you need a local git repository to hold your codes. You can create whatever name you want.
mkdir blog && cd blog
username to your own user name, and
domain.com to your domain. Furthermore, add the folder hierarchy to the last.
In the example, I use
deploy as the alias. I don’t use
origin since I have multiple remote repositories. You can use it if you wish.
From now on, every time after you writing a blog, you just simply follow the normal procedures of git,
push. Then your blogs will be automatically deploy to the server. This adopts if you maintain a static site as well.
git add -A
Thanks for reading!
Follow me (albertgao) on twitter, if you want to hear more about my interesting ideas.