How to deploy a React app to GitHub Pages?

To deploy a React app to GitHub Pages, you can follow these steps:

  1. Make sure your React app is ready for deployment by running the build command. You can do this by running npm run build or yarn build in your React app directory.

  2. Once the build is complete, create a new GitHub repository for your project if you haven't already. You can do this by going to your GitHub account, clicking on the "+" sign in the top right corner, and selecting "New repository".

  3. Push your React app code to the GitHub repository you just created. You can do this by running the following commands in your terminal:

git init git add . git commit -m "Initial commit" git remote add origin <your repository URL> git push -u origin master
  1. After pushing your code to the repository, go to the repository's settings and scroll down to the "GitHub Pages" section.

  2. In the "Source" drop-down menu, select the branch that contains your React app code (usually master or main) and click on the "Save" button.

  3. GitHub Pages will generate a URL for your deployed React app. You can visit this URL to see your app live on the web.

Your React app is now successfully deployed to GitHub Pages. You can make further changes to your app, push them to the repository, and GitHub Pages will automatically update the deployed version.