The Wayback Machine - https://web.archive.org/web/20240822105416/https://www.geeksforgeeks.org/deployment-of-react-application-using-github-pages/
Open In App

Deployment of React Application using GitHub Pages

Last Updated : 20 May, 2024
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

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?

  1. Free Hosting: GitHub Pages offers free hosting for static websites, making it an ideal choice for deploying React applications.
  2. Easy Integration: Seamlessly integrate your GitHub repository with GitHub Pages.
  3. 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.

 

Giving the name to the Repository.

 

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"
}

 

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

  1. Automatic Deployment: Set up a GitHub Actions workflow to automate the deployment process every time you push changes to the main branch.
  2. Custom Domain: Use a custom domain by adding a CNAME file to the public folder with your custom domain name.
  3. Branch Management: Ensure that the gh-pages branch is protected or managed properly to prevent unintended deletions or modifications.


Similar Reads

Deployment of Angular Application using Github Pages
There are various methods to deploy Angular Application such as Github Pages, Heroku, Firebase, etc. The Github provides the simplest way of all using the Github Pages. Steps to Create and Deploy Sample Angular Application to Github Pages: Install Node.js: a. Windows b. LinuxInstall Angular - CLICreate new project using Angular CLI: ng new gfg-exam
2 min read
Accelerated Mobile Pages (AMP pages)
As we are seeing the demand for mobile phones is very large as compared to desktops or laptops. According to some sources, India has over 1.2 billion mobile phone users that's why good organizations start focusing on mobile phones first. So a question comes to mind how we can increase performance and user experience on mobiles? Let's discuss about
5 min read
How to make “spoiler” text in github wiki pages?
GitHub Wiki pages support GitHub Flavored Markdown. Read more about GitHub flavored markdown here: Mastering MarkdownGitHub Flavored Markdown Spec However, there is no direct method to add a spoiler text in GitHub Flavored Markdown. But, there's a workaround! Approach: Markdown Supports HTML Blocks in it. So, we can use HTML's &lt;details&gt; and
1 min read
How to Build Portfolio Website And Host It on GitHub Pages?
Having an online portfolio is important for showcasing your skills and accomplishments. GitHub Pages provides a convenient and free platform for hosting your portfolio website. In this article, we will see how to build a Portfolio Website And Host It on GitHub Pages. Table of Content Creating a Portfolio WebsiteUploading into a GitHub RepositoryCre
15 min read
Publish Websites on GitHub Pages with a Custom Domain
GitHub Pages is a free hosting service provided by GitHub that allows you to publish static websites directly from your GitHub repositories. By default, GitHub Pages provides a domain in the format - username.github.io/repository, but you can also use a custom domain for your website. This article will guide you through the process of publishing we
3 min read
How to Add Custom Domain To GitHub Pages?
Adding a custom domain to your GitHub Pages site can significantly enhance its professional appearance and make it easier for your audience to remember and access. This guide will walk you through the process step-by-step, ensuring you can easily configure your custom domain and optimize your site's visibility. PrerequisitesHow to Publish a Static
2 min read
How To Add Google Analytics To GitHub Pages?
GitHub website is a great way to host websites from your GitHub repository, perfect for showing off projects or personal websites. But, it doesn't come with integrated tools to see how many users come to see your site or what they do there. To get these details, you can apply for Google Analytics. This guide will describe how to connect Google Anal
2 min read
How to Dockerize django application for production deployment with Gunicorn and Nginx
Docker is an open-source containerization platform used for building, running, and managing applications in an isolated environment. A container is isolated from another and bundles its software, libraries, and configuration files. Django is an open-source Python web framework that can be used to quickly develop fully functional web applications. I
5 min read
How to Upload a Project through GitHub Desktop on GitHub
GitHub Desktop is a user-friendly application that simplifies the process of managing your GitHub repositories on your local machine. If you’re looking to upload a project to GitHub using GitHub Desktop, this guide will walk you through the steps, making the process straightforward and accessible even for beginners. What is GitHub Desktop?GitHub De
3 min read
What are the common deployment platforms for React?
Deploying a React application is an important aspect that makes it accessible to users on the web. There are several deployment platforms and services that simplify the process of hosting and serving React applications. Some common deployment platforms for React:Netlify: Netlify is a popular platform that offers continuous deployment and hosting fo
2 min read
How to Prevent Access to Admin Pages using Node.js and React.js ?
To prevent access to admin pages using Node.js and React.js is a common task to avoid unauthorized access. In many websites, the content available to the end-user is limited until he/she proves his/her authenticity by logging in. During the development of MERN Stack Applications, when the server is linked to the client, we may want to limit the pag
6 min read
How to Deploy Angular Application to Firebase using GitHub ?
Many of us unable to showcase our small-scale or personal projects over the web. Since hosting these projects are a bit difficult and also costs a few bucks sometimes. In this article, we will show you how to deploy your Angular application at no cost without buying any domain or hosting provider. Also, tired of deploying your application every ite
3 min read
How to Deploy React App on Netlify Using Github?
React App is a web or mobile application that is built using the React library of JavaScript. It helps users create interactive, single-page, and dynamic applications. These applications are built using HTML, CSS, and JavaScript. Deployment of a React app can be done via GitHub, Netlify, or any other deployment platform. GitHub has its gh-pages, wh
6 min read
Consuming a REST API ( Github Users ) using Fetch - React Client
In this article, you will learn to develop a React application, which will fetch the data from a REST API using Fetch. We will use GitHub Users API to fetch the user's public information with their username. You can find the API reference and source code links at the end of this article. Prerequisites:NodeJS or NPMReactJSSteps to Create the React A
3 min read
How to store deployment configuration files in Node.js ?
Configuration files (CONFIG file ) are files used by various computer applications which consists of parameters which determine the settings required to run the application program successfully. Generally, they are used before writing any software application program. Every website has a specific function, such as gathering information about their
3 min read
Hot and Cold Deployment in Tomcat
What is Hot Deployment? These services can be added to or removed from the running server.it is the process to change in the currently deployed war file without re-deploying it. It is a time-saving process because the developer can simply run the build and have a new auto-deployed code instead of shutdown and startup is massive. What is Cold Deploy
1 min read
Deployment Basics in MERN
Deployment Basics in MERN are essential to learn when we are developing projects that are Full Stack Applications. It requires us to deploy the backend (ExpressJS and NodeJS) including the frontend (ReactJS), and MongoDB. In this article, we will be learning the different steps involved in deploying the MERN Stack Application. We will discuss the D
5 min read
NuxtJS Deployment
In this article, we are going to learn how we can deploy our NuxtJS app on Vercel. Nuxt.js is a free and open-source web application framework based on Vue.js, Node.js, Webpack, and Babel.js. Nuxt is inspired by Next.js, which is a framework of similar purpose, based on React.js. Nuxt gives you the ability to host your web application on vercel hos
2 min read
How to add quotations and citations to the web pages using HTML ?
In this article, we will see how to add quotations and citations to the web pages using HTML. When we are creating a website or a blog, we face many situations where we want to highlight a certain text. We can use HTML to do the same. HTML provides us with many tags such as &lt;blockquote&gt;,&lt;q&gt;, &lt;abbr&gt; and &lt;cite&gt; to perform diff
3 min read
How to navigate between web pages using javascript history API ?
In this article, we’ll look at how to use history API to navigate between pages. We use History API to navigate programmatically between web pages. History API provides us with a way to access the browser's session history. It exposes useful methods and properties that let you navigate back and forth through the user's history, and manipulate the c
2 min read
How to design navigation map for web pages using pagemap plugin ?
In this article, we will learn how to design a mini-map for navigation system with single page website using pagemap plugin. This plugin is totally a HTML, JavaScript and CSS based tool. Please download the pre-compiled library files for code implementation. The developer can fix the position of the map on the screen by the following CSS code. Add
4 min read
Animation ideas for web pages using HTML &amp; CSS
Straight forward and simple web pages are good but not the best. The animation is the thing that brings life to a static page and makes it more eye-catchy. Here are a few ideas of animation for your web pages using the frontend languages like HTML &amp; CSS. 1. Rotating a Card: The first one is rotating a card. The card has two things front side an
5 min read
How to Download a React Project from Github and Run in My PC ?
React.js is a JavaScript library that's widely popular for building dynamic user interfaces. It's an open-source project, which means that you can find a vast array of React applications and projects on GitHub. If you want to download and run a React project on your local machine, there are a few steps you can follow to do so. Below, I'll provide y
4 min read
How to Deploy Your React Websites on GitHub?
Building a web application is always exciting for developers especially when you step into the programming world for the first time. You build the front end of your application after a lot of struggle and you want to showcase your skill, your creativity, and of course your hard work to the world. Some of the folks might be familiar with the free ho
6 min read
How does React Router handle navigation in a React application?
React Router is a standard library for routing in React. It enables the navigation among views of various components in a React Application, allows changing the browser URL, and keeps the UI in sync with the URL. Let us create a simple application to React to understand how the React Router works React Router simplifies navigation in React applicat
3 min read
How to Use react-select in React Application?
React Select is a flexible and handy dropdown library for React that handles multi-select, loading data asynchronously, custom options, and more in your components with ease. In this article, we will see how to use react-select in React Application. PrerequisiteNode.js installednpm or yarn package managerBasic knowledge of ReactApproachTo implement
2 min read
How to install React-Bootstrap in React Application ?
React Bootstrap is a popular library that let us use the Bootstrap framework's power and flexibility to React.js applications. By combining the flexibility of React with the UI components provided by Bootstrap, you can create responsive and visually appealing user interfaces with ease. In this article, we'll see the process of installing React Boot
4 min read
How to convert angular 4 application to desktop application using electron ?
Using Electron JS, we can convert our existing angular project into a desktop application very easily. In this post, we will create a sample Angular project and convert it into a Desktop application step by step. Prerequisites: NPM Must be installed Environment Setup: Install Angular CLI:npm install -g @angular/cliCreate a new Angular Project. Here
3 min read
Save Pages as HTML in ElectronJS
ElectronJS is an Open Source Framework used for building Cross-Platform native desktop applications using web technologies such as HTML, CSS, and JavaScript which are capable of running on Windows, macOS, and Linux operating systems. It combines the Chromium engine and NodeJS into a Single Runtime. All Chromium browsers support saving webpages as H
6 min read
Web Pages
A webpage is a digital document that is linked to the World Wide Web and viewable by anyone connected to the internet having a web browser. It can contain any type of information, such as text, color, graphics, animations, videos, sounds, etc. A webpage is a document that is written in the HTML, it can be viewed from the Internet. It can be accesse
2 min read
three90RightbarBannerImg