https://github.com/gitname/react-gh-pages
Create an empty repository on GitHub without README File
Install the gh-pages
npm package in Terminal
npm install gh-pages --save-dev
Add it to local Choose a Folder and Add a remote
that points to the GitHub repository
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin <https://github.com/{username}/{repo-name}.git>
git push -u origin main
Create a React app
npm init react-app {appName}
Add a homepage
property to the package.json
file
{
"name": "my-app",
"version": "0.1.0",
+ "homepage": "https://{username}.github.io/{repo-name}",
"private": true,
Add deployment scripts to the package.json
file
"scripts": {
+ "predeploy": "npm run build",
+ "deploy": "gh-pages -d build",
"start": "react-scripts start",
"build": "react-scripts build",
Push the React app to the GitHub repository
npm run deploy -- -m "Deploy React app to GitHub Pages"
commit all changes
and step - 7Do commit all changes
and step - 7
Last Updated : January 27, 2024