How to Keep Your Kirby-Setup Under Git
Why do it so complicated?
Given that you want to
- use Kirby which manages it’s source-code with Git
- use a finished Theme to start right away
- to keep your content under control of Git anyway
I thought it would be nice to have everything tied together and “under control” when we’re using Git for everything anyway. Of course, one can do it without that - but that would lead to strange situations like
Oh, look at that file from a theme/snippet/younameit that I copied, I have no clue from where and which version it is.
And it get’s even worse, if you want to e.g. modify the theme a bit and keep track of your changes and those that the original author of the theme published in the public. Git makes this possible! (You can even pull in the changes from the author and automagically re-apply your changes on top of them)
But now let’s start to put a fresh Kirby installation together where everything tied together with Git:
Put the basics together
First of all, create a new empty directory for your project, then init an empty Git-Repository in it:
mkdir my-new-website cd my-new-website git init
This will be the base to add both Kirby and a template as submodules:
git submodule add git://github.com/bastianallgeier/kirbycms.git kirbycms git submodule add git://github.com/sashtown/Baseblog-Kirby-Theme.git theme/baseblog
The above shows that I’ve taken the Baseblog theme from Sascha Lack and put that into the subdirectory
theme/baseblog. This way, I can easily add other themes for testing and just switch which one to use in the config, see below.
In the top directory of your website, add a symlink to the
.htaccess file that resides in the kirbycms subdirectory:
ln -s kirbycms/.htaccess .htaccess
Nex up is to add another symlink for the assets directory of the theme you’re using:
ln -s theme/baseblog/assets assets
Configure your Kirby setup
Now copy the `ìndex.php`` from Kirby and paste it one level higher. So far I didn’t find an easy solution without having to copy that file - on the other hand, the risk that this file changes dramatically seems to be low:
cp kirbycms/index.php index.php
Now edit the copied
index.php file and make sure the following lines are changed and look like below:
$rootKirby = $root . '/kirbycms/kirby'; $rootSite = $root . '/theme/baseblog/site';
The final step before testing is now to create a content directory and fill that with some content:
mkdir -p content/01-blog/01-test cp theme/baseblog/content/01-blog/01-a-first-awesome-article content/01-blog/01-test
Of course the structure within your content directory needs to match to the chosen theme regarding the naming. But for the Baseblog-Theme, the above proposed should work.
Now you should basically be ready to go and test your new Kirby based Website in your browser.
Keeping up to date with Kirby and the linked theme
I’m using Tower, a graphical Git-Client. With that one, it’s easy to navigate to the submodules (double-click them in the left column), then fetch/pull the changes from the original repository.
Just fetch the upstream changes, then see the commit list and decide if you want those changes or not.
Put your code to a remote repository
Do you still use FTP to publish something? I don’t want to. So I propose to publish your whole setup to a remote Git repository and from now on push each and every change you make to the content or the configuration to that repository.
Based on that repository, you can even automate the publishing of your newly written posts: Just add a cron-job to e.g.
git pull your repo every 15min to your webserver.