Website Deployment with Git and Hugo
Deploying a website with Git and
Hugo (or any other static website generator for that matter) is easy.
I use a combination of Git and server-side website generation for
This has the advantage that all my files are under version control and when I am ready to deploy some changes on my website, the process is as simple as committing changes to my local repository and pushing them to my deploy target.
In case your website is not yet under version control:
cd ./website git init echo "public" >> .gitignore git add --all git commit -m "adding website to git"
Make a clone:
git clone --bare website/
Upload it to your server:
scp -r website.git email@example.com:
And add the just uploaded clone as remote:
cd website/ git remote add deploy firstname.lastname@example.org:website.git git push --set-upstream deploy master
Set-up a post-receive hook
On your server in the website.git folder:
git clone --recursive /home/git/website.git /home/git/tmp/website /usr/local/bin/hugo -s /home/git/tmp/website -d /usr/share/nginx/website -b "http://www.website.com" rm -Rf /home/git/tmp/website exit
Assuming the Hugo binary is installed in /usr/local/bin/ Folders need to be changed based on your setup.
--recursiveis needed in case your theme is a submodule of your repository.
Save and make executable.
chmod 755 post-receive
Test your deployment setup
On your local git repo:
git add --all git commit -m "some changes" git push deploy master
You should see something like that:
remote: Cloning into /home/git/tmp/jofu.org... remote: done. remote: Submodule 'themes/clean-site' (https://github.com/jf87/clean-site.git) registered for path 'themes/clean-site' remote: Cloning into themes/clean-site... remote: Submodule path 'themes/clean-site': checked out 'e9defa633ea12c0de10dfb6bbd1ec008120ccfa8' remote: 0 draft content remote: 0 future content remote: 3 pages created remote: 2 paginator pages created remote: 0 tags created remote: 0 categories created remote: in 40 ms