Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save promto-c/e46ca197f324a2148af919e18c18b5e6 to your computer and use it in GitHub Desktop.
Save promto-c/e46ca197f324a2148af919e18c18b5e6 to your computer and use it in GitHub Desktop.
Comprehensive Guides for Deploying React, Node.js, and General Web Applications on GitHub Pages

Deploying a General Web App (HTML, CSS, JS) on GitHub Pages

A step-by-step guide to deploying web applications (using HTML, CSS, JavaScript) on GitHub Pages, categorized into three main sections for ease of understanding and implementation.

Preparing Your Web Application

  1. Create Your Web Application

    • Prepare your web application with HTML, CSS, and JavaScript files. Ensure the entry point of your app is an index.html file.
  2. Organize Your Application

    • Organize your files and folders in a clean structure. For a simple application, this might just involve having an index.html file, along with directories for scripts and styles.

Setting up GitHub for Your Web App

  1. Create a GitHub Repository

    • If you don't have one, create a new repository on GitHub for your web application.
  2. Initialize and Push Your Code

    • Initialize a Git repository in your project folder:
      git init
      git add .
      git commit -m "Initial commit"
    • Link the local repository to GitHub:
      git remote add origin https://github.com/[your-github-username]/[repo-name].git
    • Push your code to the newly created GitHub repository:
      git push -u origin main

Deployment and Configuration

  1. Deploy Your Application

    • There's no need for a build step for basic HTML/CSS/JS apps. Simply push your code to GitHub.
  2. Configure GitHub Pages

    • Go to your GitHub repository's Settings > Pages.
    • Under 'Source', select the main branch (or the branch where your code resides).
  3. Access Your Deployed Web App

    • Your web application should be live at:
      https://[your-github-username].github.io/[repo-name]
      

Note

Replace [your-github-username] and [repo-name] with your actual GitHub username and your repository name. Ensure that your web application’s structure is suitable for static site hosting as offered by GitHub Pages.

Deploying a Node.js Application on GitHub Pages

A step-by-step guide to deploying Node.js applications on GitHub Pages, categorized into three main sections for ease of understanding and implementation.

Preparing Your Application

  1. Create a Node.js Application

    • Use your existing Node.js application or create a new one.
  2. Prepare Your Application

    • Navigate to your project directory:
      cd my-app
    • Add a homepage field in package.json:
      "homepage": "https://[your-github-username].github.io/[repo-name]",
    • Install gh-pages as a dev-dependency:
      npm install gh-pages --save-dev
    • Add build and deployment scripts in package.json:
      "scripts": {
        "build": "npm run your-build-script", // Replace with your actual build script
        "predeploy": "npm run build",
        "deploy": "gh-pages -d build",
        // ... other scripts
      }

Setting up GitHub

  1. Create a GitHub Repository

    • If you haven't already, create a new repository on GitHub.
  2. Initialize and Push Your Code

    • Initialize a Git repository (if not already done):
      git init
      git add .
      git commit -m "Initial commit"
    • Link your repository to GitHub:
      git remote add origin https://github.com/[your-github-username]/[repo-name].git
    • Push your code to GitHub:
      git push -u origin main

Deployment and Configuration

  1. Deploy Your Application

    • Run the deployment script:
      npm run deploy
  2. Configure GitHub Pages

    • Go to your GitHub repository's Settings > Pages.
    • Under 'Source', select the gh-pages branch.
  3. Access Your Deployed Application

    • The application should now be live at:
      https://[your-github-username].github.io/[repo-name]
      

Note

Replace [your-github-username] and [repo-name] with your GitHub username and repository name respectively. Ensure your Node.js application's build process is compatible with static hosting on GitHub Pages and that your local Git repository is correctly linked to your GitHub repository before proceeding with deployment.

Deploying a React Application on GitHub Pages

A step-by-step guide to deploying React applications on GitHub Pages, categorized into three main sections for ease of understanding and implementation.

Preparing Your React Application

  1. Create a React Application

    • If you don't have a React app, create one using:
      npx create-react-app my-react-app
    • Navigate to your project directory:
      cd my-react-app
  2. Configure the Application

    • Add a homepage field in package.json:
      "homepage": "https://[your-github-username].github.io/[repo-name]",
    • Install gh-pages as a dev-dependency:
      npm install gh-pages --save-dev
    • Add deployment scripts in package.json:
      "scripts": {
        "predeploy": "npm run build",
        "deploy": "gh-pages -d build",
        // ... other scripts
      }

Setting up GitHub for React

  1. Create a GitHub Repository

    • Create a new repository on GitHub if you haven't already.
  2. Initialize and Push Your Code

    • Initialize a Git repository:
      git init
      git add .
      git commit -m "Initial commit"
    • Link your repository to GitHub:
      git remote add origin https://github.com/[your-github-username]/[repo-name].git
    • Push your code to GitHub:
      git push -u origin main

Deployment and Configuration for React

  1. Deploy Your Application

    • Deploy your app using the script:
      npm run deploy
  2. Configure GitHub Pages

    • In your GitHub repository, go to Settings > Pages.
    • Under 'Source', select the gh-pages branch.
  3. Access Your Deployed Application

    • Your app should now be live at:
      https://[your-github-username].github.io/[repo-name]
      

Note

Replace [your-github-username] and [repo-name] with your actual GitHub username and the name of your repository. Ensure your React application is set up for deployment on GitHub Pages, and your Git repository is linked correctly to your GitHub repository.

@2226j1483
Copy link

asss

@GamingDimiGD
Copy link

didnt work for some reason

@GamingDimiGD
Copy link

didnt work for some reason

im using node js

@sinabekar
Copy link

i cant see any gh-pages branch but i did all of steps. why?

@sangsongthong-hexterika

I can see my HTML page now. Thank you. This is easy enough for me to follow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment