Deploy React to GitHub Pages: Step-by-Step Guide

Ann Jul 09, 2026

Deploying a React application to GitHub Pages can significantly enhance your project's visibility and accessibility. This step-by-step guide will walk you through the process, ensuring your React app is live and ready to impress the world.

GitHub - gitname/react-gh-pages: Deploying a React App (created using create-react-app) to GitHub Pages
GitHub - gitname/react-gh-pages: Deploying a React App (created using create-react-app) to GitHub Pages

Before we dive in, make sure you have Node.js and npm installed on your machine. Also, ensure you have a basic understanding of React and Git. Let's get started!

How To Deploy a React App on GitHub Pages (Two Different Ways)
How To Deploy a React App on GitHub Pages (Two Different Ways)

Setting Up Your React Project

First, create a new React project using Create React App, a comfortable environment for learning React, and is the best way to start building a new single-page application in React.

Deploying React Apps: A Guide to Using GitHub Pages
Deploying React Apps: A Guide to Using GitHub Pages

Open your terminal or command prompt, navigate to the directory where you want to create your project, and run:

```bash npx create-react-app my-app ```

Installing gh-pages Package

Como fazer deploy de uma aplicação do React com rotas no GitHub Pages
Como fazer deploy de uma aplicação do React com rotas no GitHub Pages

The `gh-pages` package allows you to deploy your React app to GitHub Pages. Install it as a dev dependency:

```bash cd my-app npm install --save-dev gh-pages ```

Now, let's configure the package.json file to include the `predeploy` and `deploy` scripts.

Configuring package.json

a laptop computer sitting on top of a wooden desk next to a cup of coffee
a laptop computer sitting on top of a wooden desk next to a cup of coffee

Open your `package.json` file and add the following scripts:

```json "scripts": { "predeploy": "npm run build", "deploy": "gh-pages -d build" } ```

Here, `predeploy` runs the build script before deployment, and `deploy` uses `gh-pages` to deploy the build folder to GitHub Pages.

Building and Deploying Your React App

How to Make Simple Feature Flags in React
How to Make Simple Feature Flags in React

Now that your project is set up, it's time to build and deploy your React app to GitHub Pages.

First, build your app using the following command:

a laptop computer sitting on top of a wooden desk next to a cartoon image of a man
a laptop computer sitting on top of a wooden desk next to a cartoon image of a man
How to Host a Website for Free Using GitHub Pages
How to Host a Website for Free Using GitHub Pages
Push Code to GitHub Explained 🚀
Push Code to GitHub Explained 🚀
GitHub Collaboration: Forking, Pull Requests and Shared Repositories Explained
GitHub Collaboration: Forking, Pull Requests and Shared Repositories Explained
【React】GitHubPages
【React】GitHubPages
the steps in how to write a website page for your business or company, including an email
the steps in how to write a website page for your business or company, including an email
How to Build a GitHub Portfolio That Gets Noticed
How to Build a GitHub Portfolio That Gets Noticed
The Ultimate React Hooks Cheat Sheet: 7 Hooks in One Visual Guide
The Ultimate React Hooks Cheat Sheet: 7 Hooks in One Visual Guide
React Real Projects to Deploy
React Real Projects to Deploy
the steps to creating a react app with vite
the steps to creating a react app with vite
"Learn to Build a To-Do List App with React
"Learn to Build a To-Do List App with React
Building a GitHub Repo Explorer with React and Elasticsearch
Building a GitHub Repo Explorer with React and Elasticsearch
How to Build Web Application with React
How to Build Web Application with React
Webhook Runner for Github
Webhook Runner for Github
How to build a login form in react
How to build a login form in react
60 React Project Ideas for 2026 – Beginner to Advanced | Gaurav Adhikari
60 React Project Ideas for 2026 – Beginner to Advanced | Gaurav Adhikari
Fun React Project Ideas for Beginners 🚀
Fun React Project Ideas for Beginners 🚀
the github chat sheet is displayed in this screenshote screen graber
the github chat sheet is displayed in this screenshote screen graber
Deploy React Vite apps to Netlify Easiest way
Deploy React Vite apps to Netlify Easiest way
How to Deploy a React Website on AWS S3 With GitHub Actions
How to Deploy a React Website on AWS S3 With GitHub Actions

```bash npm run build ```

This command will create a `build` folder in your project root, containing the optimized production build of your app.

Pushing to GitHub

Next, push your changes to GitHub. This will trigger the deployment process automatically if you've set up GitHub Pages in your repository settings.

To push your changes, run:

```bash git add . git commit -m "Initial commit" git remote add origin https://github.com/yourusername/your-repo-name.git git push -u origin master ```

Replace `yourusername` and `your-repo-name` with your GitHub username and repository name, respectively.

Setting Up GitHub Pages

After pushing your code, navigate to your repository on GitHub. Click on the "Settings" tab, then scroll down to the "GitHub Pages" section. Select `main` (or `master`) as the source, and click "Save".

It may take a few minutes for GitHub to deploy your app. Once it's live, you'll see the URL where your app is hosted.

Congratulations! You've successfully deployed your React app to GitHub Pages. Now, share your live app with the world and watch your project gain traction.