I just found out that my old shabby weblog running Wordpress has been exploited by some spam bots. This is not unusual - no matter if the blog is maintained or not. To deal with this whole mess, I finally abandoned Wordpress in favor of nanoc and Github pages. This is how I set up my repository:
Github pages will serve your site from the master branch, so we will use the nanoc output for our initial commit. Compile your site with nanoc3 co and move the output directory outside of your site directory. Change to the directory, initialize a new git repository with git init . and add the github remote with git remote add origin git@github.com:username/username.github.com.git. Now stage all the files with git add . and commit them with git commit -m 'Initial commit'. All the steps listed again:
nanoc3 co
mv output ..
cd ../output
git init .
git remote add origin git@github.com:username/username.github.com.git
git add .
git commit -m 'Initial commit'
git push origin master
This is not new to you, I know. :)
But of course you do want to keep your source in the repository too, so here are the steps to achieve that (found on the pages documentation):
Create a new root branch (named source in my case) and remove your old index. git clean removes all untracked files - which every file is because you just removed the index.
git symbolic-ref HEAD refs/heads/source
rm .git/index
git clean -fdx
Now you can add your site to the repository and push it to the source branch.
cp -R /path/to/your/site/ .
git add .
git commit -m 'Initial commit of source'
git push origin source
That’s it.
To deploy, you can now issue the following commands:
rm -rf output
git checkout source
nanoc3 co
git checkout master
cp -R output/* .
git add .
git commit -a -m 'I did something cool to my site'
git push origin master
git commit -a adds all files that are untracked and removes files that are not present in the working tree, so you don’t have to worry about abandoned files.
To automate this process, I use the following bash script:
#!/bin/bash
rm -rf output
git checkout source
nanoc3 co
git checkout master
cp -R output/* .
git add .
git commit -a -m "Updated site on `date`"
git push origin master
git checkout source