GitHub pages is a free service that GitHub provides to let you host website content using your GitHub repositories.
Once you've built the intermediate files for your book (in _build
) or built the HTML
for your book (in _site
), you can push your book contents to GitHub so that
others can access your book.
Prerequisites
If you are building your book's HTML manually
We assume that you have already built your book's HTML and that your HTML content is in the
_site/
folder. We also assume that you have a GitHub repository created for your book.If you are using GitHub-page's Jekyll builder
We assume that you have a GitHub repository created for your book. We also assume that your book's template and content have been pushed to your GitHub repository.
Publish your book's HTML manually to GitHub-pages
You can manually publish HTML to GitHub-pages so that it will serve a website for you. To do so, we'll need to push the HTML for our book to a branch, tell GitHub-pages that this branch contains raw HTML (not a Jekyll template), and then activate GitHub-pages on the repository. To do this, follow these steps:
- Confirm that your book's HTML is built. You should see a
collection of HTML files/folders in the
_site
folder. Install the
ghp-import
tool. This is a command-line tool for quickly pushing some built HTML to a GitHub-pages branch.pip install ghp-import
Use
ghp-import
to push your book's HTML onto thegh-pages
branch of your repository.ghp-import -n -p -f _site
The
-n
adds a.nojekyll
file to your book's built HTML, and the-p
and-f
tellghp-import
to push the contents of_site/
to thegh-pages
branch. Runghp-import -h
to see more configuration options for this tool.- Confirm that your
gh-pages
branch has newly-pushed HTML for your book. You should see a.nojekyll
file as well as the contents of_site/
in the root of yourgh-pages
branch. Enable GitHub site building for your repository.
From your GitHub repository, click
Settings
then scroll down to theGitHub Pages
section. You should see the messageYour site is published at <YOUR-URL>
. Ensure that you're building from thegh-pages
branch.Go to the URL listed at
<YOUR-URL>
and you should see your live site.
Automatically build your book's HTML with the GitHub Pages Jekyll builder
You'll need to activate GitHub-pages on your repository in order to tell GitHub to host a website from the repository's contents. To do so, follow these steps:
- Confirm that each page's HTML is built. You should see a
collection of HTML files/folders in the
_build
folder. - Commit and push the changes to your repository.
Enable GitHub site building for your repository.
From your GitHub repository, click
Settings
then scroll down to theGitHub Pages
section. You should see the messageYour site is published at <YOUR-URL>
. Ensure that you're building from the correct folder.Go to the URL listed at
<YOUR-URL>
and you should see your live site.
That should be all that is needed for GitHub Pages to automatically build
and publish your site. Any time you push changes to the _build/
folder
(by running jupyter-book build
locally and pushing the changes to GitHub),
your book content will update.