I recently moved my personal webpage from postach.io to Github pages. Postach.io is a platform that turns an Evernote notebook into a blog by transforming you notes into to webpages. Although I really love the concept, the service is relatively expensive and has not received any major updates for quite some time. Also it did not support https for custom domain.

I tested our a few options before settling for Github Pages uses the static site generator Hugo.

The following is manly for my own reference, but hopefully it will be helpful for someone else.

I wanted to setup an easy setup where I could easily push both the Hugo source files together with the generated HTML code. This can be obtained by using git subtree feature. Thanks to Jason Wong’s post “Setup Hugo on Github Pages” for a template on how to achieve this.

Setup

To setup create a new GitHub branch and configure it for github-pages using the gh-pages branch. Start out with a empty repo, this greatly simplyes the setup process (or else follow the steps from Jason Wong’s post).

#Setup git repo
mkdir <reponame> && cd <reponame>

git init
echo "Hello World" >> index.html

git add index.html
git commit -m "Initial commit"
git remote add origin git@github.com:<username>/<reponame>.git
git push -u origin master

#Create gh-pages branch

git checkout -b gh-pages
git push origin gh-pages

#Return to master branch
git checkout master 

#Setup subtree
git subtree add --prefix=public git@github.com:<username>/<reponame>.git gh-pages --squash
git subtree pull --prefix=public git@github.com:<username>/<reponame>.git gh-pages
git pull --allow-unrelated-histories

#Generate hugo site
hugo new site . --force

#Generate html
hugo 

#Commit changes and Publish site
git add -A 
git commit -a -m "Initial build" && git push
git subtree push --prefix=public git@github.com:<username>/<reponame>.git gh-pages

Page updates

To push a new update to the pages simply change the source files and run

 #Generet html
 hugo 

 #git add -A 
 git commit -a -m "Commit message" && git push 
 git subtree push --prefix=public git@github.com:<username>/<reponame>.git gh-pages

Please note that the repo has no knowledge about the subtree location, so you need to enter the full repo path. You can add this to a script. Also if you made changes to the source but are not ready to publish them just leave out the last line.

Be careful if you did changes to the gh-pages branches directly. To avoid conflict pull changes manually using

git subtree pull --prefix=public git@github.com:<username>/<reponame>.git gh-pages
git add -A
git commit -a -m "Pulled changes for gh-pages"
git puhs

Checkout on new machine

To checkout the source on a new machine you can simply run

git clone git@github:<username>/<reponame>.git