Deployment of React Application using GitHub Pages
Last Updated :
20 May, 2024
Deploying a React application using GitHub Pages is an easy and efficient way to host your projects online for free. In this article, we will walk you through the steps to deploy your React app, making it accessible to users with a live URL.
Prerequisites
GitHub Pages is a static site hosting service that takes HTML, CSS, and JavaScript files straight from a repository on GitHub, optionally runs the files through a build process and publishes a website.
Why Use GitHub Pages for Deployment?
- Free Hosting: GitHub Pages offers free hosting for static websites, making it an ideal choice for deploying React applications.
- Easy Integration: Seamlessly integrate your GitHub repository with GitHub Pages.
- Automatic Updates: Automatically update your live site by pushing changes to your repository.
How to Deploy A React app?
Step 1. Create the GitHub repository first by doing the following steps:
Click on the + sign near the profile and click on the New Repository.
.png)
Giving the name to the Repository.
.png)
Clicking on the Create repository and executing the following commands which will be shown just after clicking on the create repository on your VS code terminal.
git init
git add .
git commit -m "first commit"
git branch -M main
And then enter the following command in which we have to replace the <username> with the username of your GitHub account and the <rep Name> with the name of the repository which you have created.
git remote add origin https://github.com/<username>/<rep Name>.git
For example, git remote add origin https://github.com/vishalWaghmode/TextEdit.git
And, then enter the following commands which will push the react application to the above repository
git push -u origin main
And, then refresh the GitHub site and you will get to see the uploaded code.
Step 2. Adding the GitHub Pages dependency packages
The gh-pages package allows us to publish the build file of our application into a gh-pages branch on GitHub, where we are going to host our application. Install the gh-pages dependency using npm :
npm install gh-pages --save-dev
Step 3. Adding the properties to the package.json file
The package.json file is been configured so that we can point the GitHub repository to where our react app is been deployed. The first property we have to add is at the top of the package.json file which will be given the name "homepage", and the value for it will be in the following format:
"homepage": "https://<Username>.github.io/<Repository-name>"
Example: "homepage": "https://vishalWaghmode.github.io/Textutil"
Then we will add "deploy" and "predeploy "properties in the script field with the following values:
"scripts":{
"predeploy": "npm run build",
"deploy": "gh-pages -d build"
}
.png)
Step 4. Pushing the code updates to the GitHub repository and finally deploying the application
For pushing the updates which we have done in the code we can use the following commands:
git add .
git commit -m "commit"
git push
And now finally deploy the application using the following command in the terminal:
npm run deploy
This command will publish your application on the branch named gh-pages and can be opened by the link given in the homepage property written in the package.json file.
Step 5. View the deployed app on GitHub
Now, to view the link for opening the application we will go on the GitHub and click on Settings then at the left of the settings we can see the code and automation where the pages field will be present, just clicking it we will get the following interface where the link will be provided.

Note: If the link does not come then just wait for 2-3 minutes and then again refresh the browser and then click on the link again on it.
Tips for Managing Your Deployment
- Automatic Deployment: Set up a GitHub Actions workflow to automate the deployment process every time you push changes to the main branch.
- Custom Domain: Use a custom domain by adding a
CNAME
file to the public
folder with your custom domain name. - Branch Management: Ensure that the
gh-pages
branch is protected or managed properly to prevent unintended deletions or modifications.
Similar Reads
React Interview Questions and Answers React is an efficient, flexible, and open-source JavaScript library that allows developers to create simple, fast, and scalable web applications. Jordan Walke, a software engineer who was working for Facebook, created React. Developers with a JavaScript background can easily develop web applications
15+ min read
React Tutorial React is a powerful JavaScript library for building fast, scalable front-end applications. Created by Facebook, it's known for its component-based structure, single-page applications (SPAs), and virtual DOM,enabling efficient UI updates and a seamless user experience.Note: The latest stable version
7 min read
90+ React Projects with Source Code [2025] React, managed by Facebook and a vibrant community of developers and companies, is a JavaScript library designed to craft dynamic user interfaces. It empowers developers with concepts like React web apps, components, props, states, and component lifecycles. With a primary focus on building single-pa
12 min read
Frontend Developer Interview Questions and Answers Frontend development is an important part of web applications, and it is used to build dynamic and user-friendly web applications with an interactive user interface (UI). Many companies are hiring skilled Frontend developers with expertise in HTML, CSS, JavaScript, and modern frameworks and librarie
15+ min read
React Introduction ReactJS is a component-based JavaScript library used to build dynamic and interactive user interfaces. It simplifies the creation of single-page applications (SPAs) with a focus on performance and maintainability.It is developed and maintained by Facebook.The latest version of React is React 19.Uses
8 min read
Git Tutorial Git is an essential tool for developers, enabling them to manage and track project changes. Whether you're working on a solo project or collaborating with a team, Git keeps everything organized and under control. This Git Tutorial, from beginner to advanced, will give you a complete understanding of
12 min read
Git Cheat Sheet Git Cheat Sheet is a comprehensive quick guide for learning Git concepts, from very basic to advanced levels. By this Git Cheat Sheet, our aim is to provide a handy reference tool for both beginners and experienced developers/DevOps engineers. This Git Cheat Sheet not only makes it easier for newcom
10 min read
React Hooks ReactJS Hooks are one of the most powerful features of React, introduced in version 16.8. They allow developers to use state and other React features without writing a class component. Hooks simplify the code, make it more readable, and offer a more functional approach to React development. With hoo
10 min read
React JSX JSX stands for JavaScript XML, and it is a special syntax used in React to simplify building user interfaces. JSX allows you to write HTML-like code directly inside JavaScript, enabling you to create UI components more efficiently. Although JSX looks like regular HTML, itâs actually a syntax extensi
6 min read
React Router React Router is a library for handling routing and navigation in React JS Applications. It allows you to create dynamic routes, providing a seamless user experience by mapping various URLs to components. It enables navigation in a single-page application (SPA) without refreshing the entire page.This
6 min read