Building And Hosting A React App For Free Using Github

Posted on May 02, 2026 by Vishesh Namdev
Python C C++ Javascript React JS
Build and Host React App using GitHub Pages

Build & Host React App for FREE using GitHub Pages πŸš€ After creating your React project, the next important step is deployment. Instead of keeping your project only on localhost, you can host it online for free 🌐 GitHub Pages allows you to deploy your React app easily without any cost.
In this tutorial, we will learn:

  • How to build a React app for production
  • How to deploy React app using GitHub Pages
  • How to make your app live with a public URL
  • Best practices for deployment
  • Step 1: Build React App

    Before deploying, you need to create an optimized production build of your app.

    npm run build

    This command will create a build folder containing all optimized files.

    ---

    Step 2: Install GitHub Pages Package

    Install the gh-pages package to help deploy your app.

    npm install gh-pages --save-dev
    ---

    Step 3: Update package.json

    Add homepage and deployment scripts inside your package.json.

    "homepage": "https://your-username.github.io/your-repo-name",
    
    "scripts": {
      "predeploy": "npm run build",
      "deploy": "gh-pages -d build"
    }
    ---

    Step 4: Initialize Git & Push to GitHub

    If not already done, initialize Git and push your project to GitHub.

    git init
    git add .
    git commit -m "first commit"
    git branch -M main
    git remote add origin https://github.com/your-username/your-repo-name.git
    git push -u origin main
    ---

    Step 5: Deploy React App πŸš€

    Now run the deploy command:

    npm run deploy

    After a few seconds, your app will be live at:

    https://your-username.github.io/your-repo-name

    ---

    Step 6: Enable GitHub Pages

    Go to your GitHub repository β†’ Settings β†’ Pages Select branch: gh-pages and save.

    ---

    Important Note ⚠️

    If you are using React Router, add this in your package.json:

    "homepage": "."

    Or use HashRouter instead of BrowserRouter to avoid routing issues.

    ---

    Features and Benefits:-

  • Deploy React apps completely FREE using GitHub Pages.
  • Fast and simple deployment process.
  • Production-ready optimized build.
  • Public URL to share your project.
  • Great for portfolio and resume projects.
  • No need for paid hosting services.
  • How did you feel about this post?

    😍 πŸ™‚ 😐 πŸ˜• 😑

    Was this helpful?

    πŸ‘ πŸ‘Ž