Vinay M

#02-06 Silahis Apartments
121 Lorong K Telok Kurau
Singapore - 425762

Please send us a message and
we will get back to you within 1-2 working days.

Deploying kirby with git

Posted by on 26 July 2012 in , Read Later

I was introduced to Kirby by my good friend Nils Hendriks. Since then i fell in love with it, mainly its architecture, templating and ease-of-use. Artminister is built on kirby, fully version controlled with git.

Kirby is a file-based CMS which can be used for small and mid-sized websites. No database means, it can be easily version controlled and updated to the latest version pretty easily. I will describe my process of setting up kirby and git.

Pre-requisites

  1. Git
  2. Basic Terminal Knowledge (MacOSX) or Command Prompt (WIN)
  3. SSH Access to your server
  4. Create a gitignore file to ignore .DS_Store or other files.

Clone the kirby repository

Use Terminal to navigate to your MAMP htdocs folder

cd /Applications/MAMP/htdocs

Clone the repository using the following command

git clone git://github.com/bastianallgeier/kirbycms.git

Create a branch

The cloned repository is in its MASTER branch. We want this branch to be untouched so that kirby can be updated. So create a branch where you will start working on your new site

cd kirbycms
git checkout -b mynewbranch

This will create a new branch "mynewbranch" and will update HEAD to set the specified branch as current branch.

Create a remote Repo

Create a remote repo in your server or in github. Now, go back to your local repository, and add the newly created remote repository so it tracks from the remote repository (live).

git remote add live https://github.com/username/remoterepo.git

Note: Remote "origin" is already used by git://github.com/bastianallgeier/kirbycms.git

You can view the remote repositories using

git remote -v

Clone the remote repo to your server

SSH in to your live webserver and clone the remote repository

git clone -b mynewbranch https://github.com/username/remoterepo.git ~/public_html

A bash file to push files to github and update the server

Create a bash file in your root folder, i have it named "update.sh"

kirbycms (ROOT)
    - assets
    - content
    - kirby
    - site
    - index.php
    - .gitignore
    - .htaccess
    - update.sh

In the update.sh file add the following

git commit -am "$1"; 
git push origin mynewbranch; 
ssh -p 22 username@myserver.com "cd ~/public_html; 
git pull origin mynewbranch; 
rm -rf site/cache/* " #Clears Cache

You can now call this bash file from the terminal using

bash update.sh "Commit Message here"

Edit : July 26, 2012

Update.sh doesnt have to be in the ROOT of your website. You can keep it anywhere. Just add the following line at the top of the file.

cd /Applications/MAMP/htdocs/kirbycms;

Updating Kirby

To update kirby, go to your local repository and switch to MASTER branch

git checkout master
git pull origin master  # Pull the master branch

git checkout mynewbranch
git merge master

This will merge the master branch with your "mynewbranch". Now your local copy is updated with the latest Master branch of kirby.

So here it is my kirby and git setup. It can be easily updated to the latest version or the dev version.


Working on dev version

You can switch to the DEV branch of kirbycms using

git checkout origin/dev

Now you're in the development branch of kirby and you can test out the latest features.

Useful Links

  1. Git Flow : Use git-flow if you are working with a bigger team