Hosting a Hugo Website on GitHub Pages
Prerequisites:
- Basic Git knowledge: Understanding how to initialize a repository, commit changes, and push to a remote repository is helpful. If you're new to Git, check out a quick tutorial (there are many great ones online!)
- Installed Hugo: Make sure you have Hugo installed on your local machine. You can find installation instructions on the official Hugo website: https://gohugo.io/
Steps:
-
Create a New GitHub Repository:
- After signing in to GitHub, click the "+" button in the top right corner and select "New repository."
- Name your repository with the following format:
username.github.io
(Replace 'username' with your actual GitHub username). - Select "Public" for visibility.
- Important: Initialize the repository with a README file.
-
Set up Hugo Locally:
- Open your terminal or command prompt.
- Create a new Hugo site:
hugo new site my-hugo-site
(replace 'my-hugo-site' with your desired site name). - Navigate to your site's directory:
cd my-hugo-site
- Initialize a Git repository:
git init
-
Theme and Content:
- Choose a Hugo theme you like from https://themes.gohugo.io/ and install it following the theme's instructions.
- Start creating content using Hugo commands (
hugo new posts/my-first-post.md
)
-
Link to GitHub:
- Add your GitHub repository as a remote:
git remote add origin https://github.com/username/username.github.io.git
- Make your initial commit:
git add .
andgit commit -m "Initial commit"
- Push to GitHub:
git push -u origin main
- Add your GitHub repository as a remote:
-
Enable GitHub Pages:
- In your repository, go to Settings -> Pages
- Under "Source," select the main branch and root folder.
- Click Save.
It may take a few minutes for your site to go live. Your website will be accessible at https://username.github.io
.
Additional Notes:
-
Customize your Hugo site further by modifying the theme and adding your unique content.
-
Refer to the official Hugo documentation (https://gohugo.io/) and GitHub Pages documentation (https://pages.github.com/) for more detailed instructions and troubleshooting.