Deploy React-App to Github

Deploy React-App to Github

Table of contents

No heading

No headings in the article.

Ohh…So you build the React App, Congratulation!🔥

What next❓

Let's deploy this app to Github Pages.

But first why GitHub pages? why not something else...

If you don't know about Github Pages, it is Github's hosting service which is free of cost. You can serve any static webpage directly from your repository with it. You can host a static website on GitHub pages for free, with deploys straight from Git, because GitHub pages support custom domains.

Let's start deploying

Prerequisites:

Procedure:

1) Create an empty repository on GitHub.

  • By empty, mean without a README.md file, a .gitignore file, a LICENSE file, or any other files.

2) Open react-app in vs code and go to the src folder and open the terminal (ctr + `) or ( ctr + j ). By default, it will open windows default terminal. Change it to GitBash from the Dropmenu option.

image.png

3) Install the gh-pages package as a "dev-dependency" of the app :

image.png

4) Add some properties to the app's package.json file :

 - "homepage": "https://username.github.io/repository-name",
 - And in script object add the following :

image.png

5) Create a git repository in the app's folder and push the changes to Github using the following commands:

 - $ git init

 - $ git add .

 - $ git commit -m "Initial commit"

6) After that, add the GitHub repository as a "remote" in your local git repository:

 - $ git remote add origin https://github.com/username/repository-name.git

 *it will make it so git knows where you want to push your source code*

7) Generate a production build of your app, and deploy it to GitHub Pages

image.png

voila…..! your app deployed on Github.

8) Now go to github.com, select the repository where you deployed your react-app.

image.png

9) Open the setting tab and go to the Pages section.

image.png

here you will see hosted app link

image.png

Go to that link and you will see your app is online 🤝

Thank you.