Last Updated: January 06, 2019
·
345
· skyzyx

Updating the HTML of your GitHub Pages site with very little effort

Here is a script I use for my website, where I use Hugo to generate all of the HTML for my website into the ./public directory. I then run these commands to overwrite the contents of username.github.io with the new HTML.

git clone git@github.com:username/username.github.io.git --branch master --single-branch /tmp/master
rm -Rf /tmp/master/*
cp -Rf ./public/* /tmp/master/
touch /tmp/master/.nojekyll
echo "ryanparman.com" > /tmp/master/CNAME # If you are serving from a CNAME
find /tmp/master -type d | xargs chmod -f 0755
find /tmp/master -type f | xargs chmod -f 0644
cd /tmp/master/ && git add . && git commit -a -m "Automated commit on $$(date)" && git push origin master
rm -Rf /tmp/master

What's happening?

  1. Clone only the master branch to /tmp/master.
  2. Remove all of the contents.
  3. Add the new contents.
  4. Create a .nojekyll file so that GitHub Pages doesn't mess with my HTML.
  5. If you are serving your GitHub Pages site with a CNAME (e.g., ryanparman.com), write a CNAME text file.
  6. Change all directory permissions to 0755 and all file permissions to 0644 (a very safe set of permissions).
  7. Add and commit all, and push.
  8. Clean-up.