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?
- Clone only the
master
branch to/tmp/master
. - Remove all of the contents.
- Add the new contents.
- Create a
.nojekyll
file so that GitHub Pages doesn't mess with my HTML. - If you are serving your GitHub Pages site with a CNAME (e.g.,
ryanparman.com
), write aCNAME
text file. - Change all directory permissions to
0755
and all file permissions to0644
(a very safe set of permissions). - Add and commit all, and push.
- Clean-up.
Written by Ryan Parman
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Git
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#