Hugo hosting on github using 2 repositories
This setup requires two separate repos, one for Hugo's content, and a second one
that will be a git submodule with the public
folder's content in it.
Step by step:
-
Create on Github
<your-project>-hugo
repository (it will host Hugo’s content) -
Create on GitHub
<username>.github.io
repository (it will host the public folder: the static website) -
git clone <your-project>-hugo-url && cd <your-project>-hugo
-
Make your website work locally (hugo server)
-
Once you are happy with the results,
Ctrl+C
(kill server) andrm -rf public
(don’t worry, it can always be regenerated with hugo) -
git submodule add -b master [email protected]:<username>/<username>.github.io.git public
-
Almost done: add a
deploy.sh
script to help you (and make it executable: chmod +x deploy.sh):
If submodule already exist you can do this:
$ git submodule init
$ git pull --recurse-submodules
The deploy.sh
script:
#!/bin/sh
echo "\033[0;32mDeploying updates to GitHub...\033[0m"
# Build the project.
hugo # if using a theme, replace by `hugo -t <yourtheme>`
# Go To Public folder
cd public
# Add changes to git.
git add -A
# Commit changes.
msg="rebuilding site `date`"
if [ $# -eq 1 ]
then msg="$1"
fi
git commit -m "$msg"
# Push source and build repos.
git push origin master
# Come Back
cd ..
Run ./deploy.sh "Your optional commit message"
to send changes to
<username>.github.io
(careful, you may also want to commit changes on the
<your-project>-hugo
repo).
Source: https://gohugo.io/tutorials/github-pages-blog/