This guide explains how to update, build, and publish your Hugo blog to GitHub Pages.
-
Hugo Installed:
- Check with:
hugo version
- Install: Hugo Installation Guide
- Check with:
-
Git Installed:
- Check with:
git --version
- Install: Git Installation Guide
- Check with:
-
GitHub Repository:
- A repository with GitHub Pages enabled (either
username.github.io
or a project repo).
- A repository with GitHub Pages enabled (either
-
Remote Repository Set:
- Check with:
git remote -v
- If not set:
git remote add origin https://github.com/username/repository.git
- Check with:
-
Pull the Latest Changes (Optional):
git pull origin main
-
Make Changes:
- Add or edit content in
content/
- Update config in
config.toml
- Add or edit content in
-
Check Changes Locally:
hugo server -D
- Open
http://localhost:1313
in your browser.
- Open
When you're ready to deploy:
-
Clean and Build the Site:
hugo --minify
- This generates the site in the
public/
folder.
- This generates the site in the
-
Verify Output:
hugo server --source public
- Check
http://localhost:1313
to verify the built version.
- Check
-
Commit Your Changes:
git add . git commit -m "Update blog content" git push origin main
-
Push
public/
Folder togh-pages
:git subtree push --prefix public origin gh-pages
-
Verify Deployment:
- Go to:
https://username.github.io/
orhttps://username.github.io/repository/
- Go to:
-
Commit and Push:
git add . git commit -m "Update blog" git push origin main
-
GitHub Pages Settings:
- Go to Settings → Pages.
- Set Source to
main
branch (orgh-pages
if using that).
-
Visit Your Site:
https://username.github.io/
If things don't work as expected:
-
Clear
public/
Folder:rm -rf public/ hugo --minify
-
Force Push:
git add . git commit -m "Clean build" git push origin main --force
-
Page Not Updating?
- Clear browser cache.
- Verify
gh-pages
branch is up-to-date.
-
Build Errors?
- Run
hugo
without--minify
to see detailed errors.
- Run
-
404 Errors on Subpages?
- Make sure
baseURL
inconfig.toml
is correct.
- Make sure
# Start local server
hugo server -D
# Build site
hugo --minify
# Deploy to gh-pages
git subtree push --prefix public origin gh-pages
# Clean public folder
rm -rf public/
Happy blogging! 🚀