How to Deploy a Website on GitHub: A Step-by-Step Guide Using GitHub Pages

GitHub isn’t just for code hosting and collaboration — it also offers a powerful way to deploy static websites for free through GitHub Pages. Whether you’re building a personal portfolio, documentation site, or demo project, GitHub makes deployment simple and fast.

In this guide, you’ll learn how to deploy your website to GitHub using GitHub Pages.


🚀 What Is GitHub Pages?

GitHub Pages is a feature that allows you to host static websites directly from a GitHub repository. It’s ideal for HTML, CSS, and JavaScript projects, and supports frameworks like Jekyll, Hugo, and more.

Key Benefits:

  • Free hosting
  • Custom domain support
  • Automatic HTTPS
  • Seamless integration with GitHub workflows

✅ Prerequisites

Before you begin, you’ll need:

  • A GitHub account
  • Git installed on your local machine
  • A website project (HTML/CSS/JS files) ready to deploy

🛠️ Step-by-Step: How to Deploy a Website on GitHub

Step 1: Create a GitHub Repository

  1. Go to github.com and log in.
  2. Click “New repository”.
  3. Name your repo (e.g., my-website).
  4. (Optional) Add a description.
  5. Select Public (required for free GitHub Pages).
  6. Click “Create repository”.

Step 2: Push Your Website Code to the Repository

In your terminal:

cd path/to/your-website-folder
git init
git remote add origin https://github.com/your-username/my-website.git
git add .
git commit -m "Initial commit"
git push -u origin master

Replace your-username and my-website with your actual GitHub username and repo name.


Step 3: Enable GitHub Pages

  1. Go to your repository on GitHub.
  2. Click the “Settings” tab.
  3. Scroll down to “Pages” (or go to https://github.com/your-username/my-website/settings/pages).
  4. Under “Source”, choose:
    • main or master branch
    • /root (or /docs if your files are in a folder called docs)
  5. Click “Save”.

GitHub will now build and deploy your site.


Step 4: Access Your Live Website

After a few seconds, you’ll see a message like:

Your site is published at https://your-username.github.io/my-website/

Click the link to view your live site!


🧠 Advanced Tips

  • Custom Domain: Add a CNAME file or configure DNS for your domain in the Pages settings.
  • 404 Pages: Add a 404.html to customize error handling.
  • Theme Support: Use Jekyll themes if you want a quick design setup.

🧹 Best Practices

  • Keep your HTML/CSS clean and organized
  • Use version control (commits, branches) for updates
  • Add a .gitignore to exclude files like node_modules
  • Minify assets for faster performance

🔁 Automate Deployment (Optional)

For projects using build tools like React, Vue, or static site generators, use GitHub Actions to automate the build and deploy process.

Example: For React, you can use the gh-pages package to publish your build folder.


✅ Summary

StepDescription
1Create a GitHub repo
2Push your code via Git
3Enable GitHub Pages in repo settings
4Visit the published URL

Conclusion

Deploying a website on GitHub is one of the easiest and most cost-effective ways to get your site online. With just a few commands and clicks, your project can go from local development to live on the web — no hosting plan required.

Sharing Is Caring:

Leave a Comment