How to deploy a create react app to Github pages

1. Add homepage

Open your package.json file present inside your react app and add homepage property.


replace the above url with your github username and repository name.

2. Install gh-pages

Next, we need to install a package called gh-pages.

npm install --save-dev gh-pages

3. Deploy script

It’s time to add a deploy script commands in our package.json file.

 "predeploy": "npm run build",
 "deploy": "gh-pages -d build",

Now in your terminal run npm run deploy

4. Setup source to gh-pages branch.

Once you successfully deployed open your GitHub code repository and click on settings tab if you scroll down you can see a GitHub Pages then choose a branch to gh-pages.

That’s it now you can see your react app URL like in the above image.