How to Create and Publish a Quarto Book on GitHub
Quarto is designed to be versatile, supporting multiple environments beyond just R. In this tutorial, we’ll explore how to use Visual Studio Code (VS Code) to create and publish a Quarto book. This method should work similarly across different operating systems.
Prerequisites
Before you begin, ensure you have:
- A GitHub account.
- VS Code installed.
- Quarto installed on your machine.
This tutorial is conducted on Ubuntu, but the process should be similar on other operating systems.
Creating Your Quarto Book
- Open VS Code and press
Ctrl + P
to open the command palette. Execute the Quarto: Create Project command and select Book Project. You will be prompted to select a parent directory and name your book project directory.
More information on creating a Quarto book can be found in the official Quarto documentation.
Setting Up GitHub
- Go to GitHub and create a new repository. Name it after your Quarto book and set it to public.
Link your local Quarto book project to your GitHub repository by executing the following commands in your terminal:
1 2 3 4 5 6 7 8
echo "# Your-Quarto-Book-Title" >> README.md git init git add README.md git commit -m "first commit" git branch -M main git remote add origin <https://github.com/yourusername/your-quartobook.git> git push -u origin main
- Create a branch called
gh-pages
from your GitHub repository. In your repository settings on GitHub, select Pages from the left menu, set the source to deploy from the
gh-pages
branch.Check the Actions menu on GitHub; it should start processing.
Publishing Your Book
- In VS Code, navigate to your project directory and create a
.github/workflows
directory. Inside this, create apublish.yml
file by runningtouch publish.yml
in your terminal. Add the following GitHub Action configuration to
publish.yml
to automate the publishing process:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
on: workflow_dispatch: push: branches: main name: Quarto Publish jobs: build-deploy: runs-on: ubuntu-latest permissions: contents: write steps: - name: Check out repository uses: actions/checkout@v4 - name: Set up Quarto uses: quarto-dev/quarto-actions/setup@v2 - name: Render and Publish uses: quarto-dev/quarto-actions/publish@v2 with: target: gh-pages env: GITHUB_TOKEN: $
This action will run whenever you push to the main branch or manually trigger it from the Actions tab. It renders your content and publishes it to GitHub Pages.
Freeze Computations by adding the following to your
_quarto.yml
to ensure that R, Python, and Julia code is executed locally:1 2 3
execute: freeze: auto
- Locally run
quarto publish gh-pages
to generate the necessary_publish.yml
configuration. - Stage, commit, and push all changes to GitHub. Check your repository’s GitHub Pages section to confirm the publication status.
- Populate your book with content, and it should now be available at the GitHub Pages URL assigned to your repository.
This guide should help you successfully create and publish a Quarto book using VS Code and GitHub.