My take on GoHugo and Github.io mirroring
In these days I worked on setting up a mirror for this blog on github.io, in this post I’ll explain how I set it up.
Log in on your github.com account and create these repositories:
yourwebsite.com: this will contain your whole hugo directory and it will contain the config.toml file with the domain
yourgithubname.github.io: this will be the mirror itself, it will be the public/ directory inside your hugo dir, generated with the github.io domain inside the config.toml.
yourhugotheme: your theme folder in themes/, you can fork it if you’re using a theme made by someone else :).
NOTE that all of the above repositories can be private, and that’s sweet.
After creating the repositories copy your whole hugo folder in
Then copy the contents of your theme directory in
Create a dummy file on
yourgigthubname.github.io to make it not empty.
Commit and push and go on the next step.
You need to “link” the repositories together, we are going to do it using git submodule.
yourwebsite.com run these commands
Now we need to be able to sync the stuff from your computer to the repos, then from the repos to the server. The first step is easy, just use git. The latter is a little bit more tricky if the repositories are private.
If that’s not the case, skip this step.
Create a ssh-key on the server using
ssh-keygen, then go to your private
Deploy Keys and
Add deploy key.
NOTE I suggest to add it in Read-Only, you don’t want to give the server push privileges on your repository.
Clone everything (not really)
yourwebsite.com on your server without the
You don’t need to use the
--recursive flag because your server doesn’t need
public/ directory since it is actually the github mirror.
yourwebsite.com root create this two scripts.
Use this script from the server to sync the changes and deploy.
Use this script from your computer to deploy the changes to the github mirror.
The end (?)
No, the start! Now you can work from your pc and easilly deploy to both github and your server :D