If you haven't already, navigate to your React project folder and install the gh-pages package:
npm install gh-pages --save-devEdit your package.json file and add the following lines:
-
Set the homepage property (Replace
usernameandrepo-namewith your GitHub username and repository name):"homepage": "https://username.github.io/repo-name"
-
Add deploy scripts:
"scripts": { "predeploy": "npm run build", "deploy": "gh-pages -d build" }
Ensure your project is a Git repository and push it to GitHub:
git init
git add .
git commit -m "Initial commit"
git branch -M main
git remote add origin https://github.com/username/repo-name.git
git push -u origin mainRun the following command:
npm run deployThis will create a build folder and push the contents to the gh-pages branch.
- Go to your GitHub repository.
- Navigate to Settings > Pages.
- Under Source, select
gh-pagesbranch. - Click Save.
Once the deployment is complete, visit:
https://username.github.io/repo-name
Your React app is now live on GitHub Pages! 🚀