How to host Hugo site from private repository
Usually, in order to utilize GitHub Pages for free hosting my Hugo site, I have to make the repository public. However, this also implies that even my draft posts will become visible in the public site repository. That is definitely not the way I prefer to do this.
After some searching, I found out that I can hide my draft posts and publish only the static site to the public repository by using GitHub Actions:
- A private repository(Just turn the present public repository of Hugo site into private repository)
- A newly created public repository to publish Hugo site
- GitHub Personal token
Click on your GitHub avatar in top-right and open
Developer settings(at the bottom of the page).
Personal access tokens->
Generate new token->
Generate new token(classic).Use personal tokenPersonal token is required because we need the permission to access to a external repository.
Add a note for token. Select expiration.
- ✅ workflow
- ✅ write:packages
Copy the token start with
Settingsof private repository.
Secrets and variables->
New repository secret
Add name then paste the token to the
Here is the workflow configuration file I made for my Hugo site:
Replace the configuration file under
.github/workflows with it. Then push the changes to private repository and check whether the workflow runs successfully.
This way, I can push all the content, including draft posts, drawio files, and other files related to my site, to my private repository without worrying about they being made public.
If you have any questions or advice, leave me a comment below and I will try my best to respond!