logo
Published on

Deploy a Next.js app to GitHub Pages

Authors

Not long ago I made the decision to start sharing my dev experiences in a blog, and why not starting by describing the steps I took to get a Next.js app (This Blog) deployed to GitHub Pages.

The app I am using is a stater template cloned from Vercel templates.

Create a repository

  1. First, start by creating a public repository in GitHub using the following naming convention <github_username>.github.io. The repository name must start with your username to work.
create repo
  1. Clone the repository using your git client of preference.
clone repo
  1. Create or add your existing Next.js app to the repository. In my case, I cloned the starter template from Vercel templates and updated the code to my taste.

add app
  1. Ensure your app is running locally.

This app uses yarn package manager, so I ran the following command to test it works in the browser.


yarn dev 

run app
  1. Once tested, commit and push your changes to GitHub
push repo

Configure Pages

  1. In GitHub, go to the <github_username>.github.io repository and navigate to Settings > Pages.
settings pages repo
  1. Under Build and deployment section, click on the Source dropdown and choose GitHub Actions.
github actions pages repo
  1. A new GitHub workflow will display underneath. Click on Configure button
workflow
  1. This workflow will run every time a commit is made to the main branch, building and deploying your app as soon as it happens.

Save workflow by clicking on Commit Changes button.

workflow confirmation
  1. Add your commit message and click on Commit Changes
commit workflow
  1. Navigate to Actions tab and check the deployment progress.

deploy progress
  1. Once deployment is complete, you can navigate to the URL provided in the deploy job.

deploy complete
  1. And this is it! You have a Next.js app running in GitHub Pages
pages live