This is a step-by-step guide on how to use Hugo to create a blog site, manage your content and configuration in a private GitHub repository, and deploy it to Cloudflare Pages, which offers global CDN acceleration and built-in web security.
1. Create a New Hugo Site
Follow the official Hugo Quick Start Guide to set up your new site. Make sure to initialize Git and add your theme as a submodule. Do remember to do the git related commands:
git init
git submodule add https://github.com/theNewDynamic/gohugo-theme-ananke.git themes/ananke
2. Add a .gitignore File
In your Hugo project directory, create a .gitignore file to exclude generated and unnecessary files:
### Hugo ###
# Generated files by Hugo
/public/
/resources/_gen/
/assets/jsconfig.json
hugo_stats.json
# Temporary lock file while building
/.hugo_build.lock
3. Create a Private GitHub Repository
Create a new private repository on GitHub. Leave it empty — do not add a README, .gitignore, or license file.
Example: https://github.com/foobar/cfpage-hugo-ws
4. Push Your Hugo Site to GitHub
In your local Hugo project directory, add your GitHub repository as a remote, switch to the master branch, then commit and push your project:
git remote add origin https://github.com/foobar/cfpage-hugo-ws.git
git branch -M master
git add .
git commit -m "Initial commit"
git push origin master:master
5. Use Git for Version Control
You now have a version-controlled Hugo workspace hosted privately on GitHub. Whenever you make changes or add new content, use Git to commit and push your updates:
git add .
git commit -m "Your message here"
git push origin master:master
6. Clone and Initialize Submodules on a New Machine
When cloning the repository on a new machine, make sure to initialize and update the theme submodule:
git clone https://github.com/foobar/cfpage-hugo-ws.git
cd cfpage-hugo-ws
git submodule init
git submodule update
git submodule update --remote --merge
7. Set Up Cloudflare Pages
Create a Cloudflare account and optionally register your own domain. Connect your GitHub account by following this guide.
8. Deploy Your Site to Cloudflare Pages
Follow this guide to deploy your Hugo site. When setting up your Pages project, be sure to define the following environment variables under Pages Project > Settings > Environment Variables:
GO_VERSION: 1.24.3
HUGO_VERSION: 0.147.6
With this setup, your Hugo blog’s workspace will be version-controlled, securely stored in a private GitHub repository, and your blog contents globally published and served via Cloudflare CDN.