2019-10-21 04:22:28 -04:00
---
title: Host on GitHub
linktitle: Host on GitHub
2021-02-18 11:52:49 -05:00
description: Deploy Hugo as a GitHub Pages project or personal/organizational site and automate the whole process with Github Action Workflow
2019-10-21 04:22:28 -04:00
date: 2014-03-21
publishdate: 2014-03-21
categories: [hosting and deployment]
keywords: [github,git,deployment,hosting]
authors: [Spencer Lyon, Gunnar Morling]
menu:
docs:
parent: "hosting-and-deployment"
weight: 30
weight: 30
sections_weight: 30
toc: true
aliases: [/tutorials/github-pages-blog/]
---
2021-02-18 11:52:49 -05:00
GitHub provides free and fast static hosting over SSL for personal, organization, or project pages directly from a GitHub repository via its [GitHub Pages service][] and automate development workflows and build with [GitHub Actions].
2019-10-21 04:22:28 -04:00
## Assumptions
1. You have Git 2.8 or greater [installed on your machine][installgit].
2. You have a GitHub account. [Signing up][ghsignup] for GitHub is free.
3. You have a ready-to-publish Hugo website or have at least completed the [Quick Start][].
## Types of GitHub Pages
2021-02-18 11:52:49 -05:00
There are two types of GitHub Pages:
2019-10-21 04:22:28 -04:00
- User/Organization Pages (`https://< USERNAME | ORGANIZATION > .github.io/`)
- Project Pages (`https://< USERNAME | ORGANIZATION > .github.io/< PROJECT > /`)
Please refer to the [GitHub Pages documentation][ghorgs] to decide which type of site you would like to create as it will determine which of the below methods to use.
## GitHub User or Organization Pages
2020-05-06 06:12:21 -04:00
As mentioned in the [GitHub Pages documentation][ghorgs], you can host a user/organization page in addition to project pages. Here are the key differences in GitHub Pages websites for Users and Organizations:
2019-10-21 04:22:28 -04:00
1. You must use a `<USERNAME>.github.io` to host your **generated** content
2020-11-27 03:26:24 -05:00
2. Content from the `main` branch will be used to publish your GitHub Pages site
2019-10-21 04:22:28 -04:00
This is a much simpler setup as your Hugo files and generated content are published into two different repositories.
2021-02-18 11:52:49 -05:00
## Build Hugo With GitHub Action
2019-10-21 04:22:28 -04:00
2021-02-18 11:52:49 -05:00
GitHub execute your software development workflows. Everytime you push your code on the Github repository, Github Action will build the site automatically.
2019-10-21 04:22:28 -04:00
2021-02-18 11:52:49 -05:00
Create a file in `.github/workflows/gh-pages.yml` containing the following content (based on https://github.com/marketplace/actions/hugo-setup ):
2019-10-21 04:22:28 -04:00
2021-02-18 11:52:49 -05:00
```yml
name: github pages
2019-10-21 04:22:28 -04:00
2021-02-18 11:52:49 -05:00
on:
push:
branches:
- main # Set a branch to deploy
2019-10-21 04:22:28 -04:00
2021-02-18 11:52:49 -05:00
jobs:
deploy:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
with:
submodules: true # Fetch Hugo themes (true OR recursive)
fetch-depth: 0 # Fetch all history for .GitInfo and .Lastmod
2019-10-21 04:22:28 -04:00
2021-02-18 11:52:49 -05:00
- name: Setup Hugo
uses: peaceiris/actions-hugo@v2
with:
hugo-version: 'latest'
# extended: true
2019-10-21 04:22:28 -04:00
2021-02-18 11:52:49 -05:00
- name: Build
run: hugo --minify
2019-10-21 04:22:28 -04:00
2021-02-18 11:52:49 -05:00
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./public
2019-10-21 04:22:28 -04:00
```
2021-03-21 08:31:17 -04:00
For more advanced settings https://github.com/marketplace/actions/hugo-setup
2019-10-21 04:22:28 -04:00
## Use a Custom Domain
2021-02-18 11:52:49 -05:00
If you'd like to use a custom domain for your GitHub Pages site, create a file `static/CNAME` . Your custom domain name should be the only contents inside `CNAME` . Since it's inside `static` , the published site will contain the CNAME file at the root of the published site, which is a requirement of GitHub Pages.
2019-10-21 04:22:28 -04:00
Refer to the [official documentation for custom domains][domains] for further information.
[config]: /getting-started/configuration/
[domains]: https://help.github.com/articles/using-a-custom-domain-with-github-pages/
[ghorgs]: https://help.github.com/articles/user-organization-and-project-pages/#user--organization-pages
2020-11-27 03:26:24 -05:00
[ghpfromdocs]: https://help.github.com/articles/configuring-a-publishing-source-for-github-pages/
2019-10-21 04:22:28 -04:00
[ghsignup]: https://github.com/join
[GitHub Pages service]: https://help.github.com/articles/what-is-github-pages/
[installgit]: https://git-scm.com/downloads
2020-11-27 03:26:24 -05:00
[orphan branch]: https://git-scm.com/docs/git-checkout/#Documentation/git-checkout.txt---orphanltnewbranchgt
2019-10-21 04:22:28 -04:00
[Quick Start]: /getting-started/quick-start/
[submodule]: https://github.com/blog/2104-working-with-submodules
[worktree feature]: https://git-scm.com/docs/git-worktree
2021-02-18 11:52:49 -05:00
[GitHub Actions]: https://docs.github.com/en/actions