Deploying a React app to GitHub Pages is straightforward. Here's a step-by-step guide:
✅ Step 1: Prepare Your React App
Make sure your React app is working locally. This assumes you created it using create-react-app.
✅ Step 2: Install GitHub Pages Package
In the root of your project:
npm install --save gh-pages
✅ Step 3: Update package.json
Modify your package.json file with the following:
Add the homepage field at the top:
"homepage": "https://<your-username>.github.io/<repository-name>"
Add scripts:
"scripts": {
  "predeploy": "npm run build",
  "deploy": "gh-pages -d build"
}
✅ Step 4: Push Your App to GitHub
If your app is not already in a GitHub repo, initialize and push it:
git init
git remote add origin https://github.com/<your-username>/<repository-name>.git
git add .
git commit -m "Initial commit"
git push -u origin main
✅ Step 5: Deploy to GitHub Pages
Run:
npm run deploy
This will:
- Build the app
 - Push the build folder to the 
gh-pagesbranch - Make the app live at the URL you specified in the homepage field
 
✅ Step 6: Enable GitHub Pages in Repo Settings
Go to your GitHub repo:
- Click Settings > Pages
 - Under Source, select 
gh-pagesbranch and click Save 
✅ Step 7: Access Your App
It will be live at:
https://<your-username>.github.io/<repository-name>
    
Top comments (1)
Thanks for sharing. ❤️