Readers who read this content need to configure a local runnable blog first. Note that all <username>
mentioned below should be changed to your github username, and no <> is required,
Warehouse settings on Github Link to heading
First, you need to create a warehouse named <username>.github.io
and set it to public. (Some online tutorials here say to set up a private repository to store md files, but the author found that the public files generated by hugo are html files themselves, and there is no md file to upload, so there should be no need to worry about source code leakage)
Check the baseURL
configuration
Link to heading
You need to change the first line of hugo.toml
to
baseURL = "https://<username>.github.io/"
Then run below code in the command line.
# Delete the public folder and regenerate the website
#(If you don't have a public folder, you don't need to delete it)
rm -rf public/
hugo
# Push updates to GitHub
git remote add origin https://github.com/<username>/<username>.github.io.git
git add .
#This is equivalent to a comment to github, which can be modified by yourself
git commit -m "deploy"
#If the branch you push is not called main, you need to rename it here
git push --force origin master:main
If git remote add ···
reports an error error: remote origin already exists.
This means that you have added a remote repository before.
You can run
git remote -v
to verify this statement
You need to delete first and then add, delete:
git remote rm origin
Then git remote add ···
, then add., commit, push, wait patiently for the upload to succeed, and then in the GitHub repository
Setting->(Code and automation)Pages
Select deploy from a branch in Build and deployment, and select your main.
After that, wait a moment and you can see the generated website in GitHub Pages.