RepositoryTypeScript
gregrickaby

gregrickaby/nextjs-github-pages

🚀 Deploy a Next.js app to GitHub Pages via GitHub Actions

562stars
72forks
0issues
1views

Featured achievements

The project's latest awards

1
TINIX TRENDING·Topic: static-site

#1 Repository of the week

2
TINIX TRENDING·Topic: github-pages

#2 Repository of the week

2
TINIX TRENDING·Topic: github-pages

#2 Repository of the month

Next.js GitHub Pages

Deploy Next.js to GitHub Pages with GitHub Actions. View the deployed app 🚀

⚠️ Heads up! GitHub Pages is not a Node.js server. So dynamic logic that cannot be computed during the build process, are not supported! See all the unsupported features.


Configure Next.js

Next.js Config

First, you need to configure Next.js to deploy static exports. This is required for GitHub Pages to work.

  1. Open the next.config.ts file
  2. Add the following:
import type { NextConfig } from "next";

const nextConfig: NextConfig = {
  /**
   * Enable static exports.
   *
   * @see https://nextjs.org/docs/app/building-your-application/deploying/static-exports
   */
  output: "export",

  /**
   * Set base path. This is the slug of your GitHub repository.
   *
   * @see https://nextjs.org/docs/app/api-reference/next-config-js/basePath
   */
  basePath: "/nextjs-github-pages",

  /**
   * Disable server-based image optimization. Next.js does not support
   * dynamic features with static exports.
   *
   * @see https://nextjs.org/docs/app/api-reference/components/image#unoptimized
   */
  images: {
    unoptimized: true,
  },
};

export default nextConfig;
  1. Save the next.config.ts

  2. Finally, place a .nojekyll file in the /public directory to disable GitHub Pages from trying to create a Jekyll website.

.
├── app/
├── public/
│   └── .nojekyll
├── next.config.ts

Perfect! This is all you need to configure Next.js to deploy on GitHub Pages.

Add base path to page.tsx

Next, you will need to add the base path to images in page.tsx file. This is required for the images to appear on GitHub Pages.

  1. Open app/page.tsx
  2. Find the Image components
  3. Add /nextjs-github-pages/ (or the slug of your GitHub repository) to the src prop:
<Image
  src="/nextjs-github-pages/vercel.svg"
  alt="Vercel Logo"
  className={styles.vercelLogo}
  width={100}
  height={24}
  priority
/>
  1. Save the page.tsx file

Learn more by reading the official documentation for basePath and images.


Configure GitHub Repository

Now that Next.js is configured, you need to set up your GitHub repository to deploy to GitHub Pages.

Setup GitHub Action

This is where the magic happens! This workflow file will automatically build and deploy the app when you push to the main branch.

  1. Create .github/workflows/deploy.yml file
  2. Paste the contents of https://github.com/gregrickaby/nextjs-github-pages/blob/main/.github/workflows/deploy.yml
  3. Save the deploy.yml file

Enable GitHub Pages

  1. Go to your repository's Settings tab
  2. Click "Pages" in the sidebar
  3. Under "Build and Deployment", select "GitHub Actions" as the source:

screenshot of github pages settings

Push to GitHub

Now that everything is configured, you can commit your code and push to GitHub. This will trigger the GitHub Action workflow and deploy your app to GitHub Pages.

git add . && git commit -m "initial commit" && git push

You should see your site deployed to GitHub Pages in a few minutes. 🚀


Wrap up

Thanks for reading and I hope this helps. If you noticed something wrong, please open an issue. Cheers! 🍻


Similar Projects

Discover other similar projects and AI models.

RepositoryTypeScript
peaceiris/actions-gh-pages

GitHub Actions for GitHub Pages 🚀 Deploy static files and publish your site easily. Static-Site-Generators-friendly.

5.4k
Nov 28, 2026
RepositoryTypeScript
JamesIves/github-pages-deploy-action

🚀 Automatically deploy your project to GitHub Pages using GitHub Actions. This action can be configured to push your production-ready code into any branch you'd like.

4.6k
Dec 1, 2026
RepositoryRuby
community/community

Public feedback discussions for: GitHub Mobile, GitHub Discussions, GitHub Codespaces, GitHub Sponsors, GitHub Issues and more!

9.0k
Nov 30, 2026
RepositoryJupyter Notebook
github/covid19-dashboard

A site that displays up to date COVID-19 stats, powered by fastpages.

1.6k
May 26, 2024
RepositoryHTML
jekyllt/jasper2

Full-featured Jekyll port of Ghost's default theme Casper v2 👻

771
May 30, 2024
RepositoryPython
521xueweihan/HelloGitHub

:octocat: 分享 GitHub 上有趣、入门级的开源项目。Share interesting, entry-level open source projects on GitHub.

192.6k
Nov 27, 2026
RepositoryPython
langgenius/dify

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

162.3k
Dec 2, 2026
RepositoryJavaScript
vercel/next.js

The React Framework

143.9k
Dec 1, 2026
RepositoryJavaScript
vercel/next.js

The React Framework

143.9k
Dec 1, 2026