For publishing a website free of cost, GitHub Pages makes it possible to host a website for free, whether it’s a personal portfolio, resume, or project showcase. With just a GitHub account and your website files, you can take your HTML, CSS, and JavaScript live in minutes, no hosting fees required. In this guide, we’ll walk you through how to host a website for free with GitHub Pages, step by step, from creating a repository to going live with your URL.
What is GitHub Pages?
GitHub Pages is a free web hosting service provided by GitHub that allows you to publish static websites directly from a GitHub repository. It’s perfect for hosting personal portfolios, documentation, blogs, and project pages without the need for paid hosting or complex server setups.
Unlike traditional hosting, GitHub Pages is designed for static content only, meaning it serves files like HTML, CSS, JavaScript, and images, but not dynamic server-side scripts like PHP or databases. You simply upload your website files to a GitHub repository, enable GitHub Pages, and your site goes live under a URL like:
https://yourusername.github.io
Because GitHub Pages integrates seamlessly with version control, it’s especially popular among developers, designers, and students who want an easy way to keep their sites updated and in sync with their code.
Prerequisites
Before you start hosting your website on GitHub Pages, make sure you have a few essentials ready:
A GitHub Account: Sign up for a free account at github.com if you don’t already have one.
Basic GitHub Knowledge: You don’t need to be an expert, but understanding how to create repositories, upload files, and commit changes will help.
Your Website Files: Prepare your static site files (HTML, CSS, JavaScript, images). GitHub Pages only supports static content, so frameworks like React or tools like Jekyll require extra setup.
Optional: Git Installed on Your Computer: If you prefer using the command line to push updates instead of the GitHub web interface, having Git installed is handy.
With these basics in place, you’re ready to set up your repository and publish your site for the world to see.
Step-by-Step Guide to Hosting a Website on GitHub Pages
Follow these simple steps to take your website live using GitHub Pages completely free.
Step 1: Create a GitHub Repository
-
Log in to your GitHub account.
-
Click the “+” icon (top-right corner) → New repository.
-
Name your repository.
-
For a personal website, use this exact format:
yourusername.github.io
(Replace yourusername with your GitHub username.) -
For project-specific websites, you can use any name.
-
-
Set the repository to Public (GitHub Pages won’t work on private repos unless you’re on a paid plan).
-
Click Create repository.
Step 2: Upload Your Website Files
There are two easy ways to add your site’s files:
Option A: Upload via GitHub’s Web Interface
-
Open your repository → Click Add file → Upload files.
-
Drag-and-drop your HTML, CSS, JS, and images.
-
Commit the changes by clicking Commit changes.
Option B: Use Git on Your Computer (for developers)
git clone https://github.com/yourusername/your-repo.git
cd your-repo
# Add your files
git add .
git commit -m "Initial commit"
git push origin main
Step 3: Enable GitHub Pages
-
Go to your repository’s Settings tab.
-
Scroll down to Pages (or find “Pages” in the left menu).
-
Under Source, select the branch you want to publish (usually
main
). -
Leave the folder as
/root
(unless your site is inside a subfolder like/docs
). -
Click Save.
Step 4: Access Your Live Website
-
After a few seconds, GitHub Pages will generate a link for your site.
-
You’ll see a green success banner with your live URL, like:
https://yourusername.github.io/ -
Click the link, and your website is live!
This basic setup works for static websites instantly. If you want a custom domain name, GitHub Pages also supports that (covered in the next section).
Tips & Best Practices
Hosting your site on GitHub Pages is simple, but following a few best practices will make your site easier to manage and look more professional:
1. Keep Your Repository Organized
Structure your files neatly (HTML, CSS, JS in clear folders like /assets
or /css
). A clean repo makes updates easier and keeps things readable for others who might view your code.
2. Write a Clear README.md
Add a README file to explain what your website is about. This is useful if you share your repo with collaborators, or if future employers look at your GitHub profile.
3. Use Branches Wisely
Consider using a separate development branch for testing changes before merging them into main
the branch that GitHub Pages publishes. This prevents broken code from going live.
4. Take Advantage of Jekyll
GitHub Pages supports Jekyll, a static site generator. If you want features like blogging, themes, or templates, you can easily integrate Jekyll without needing a separate hosting setup.
5. Enable HTTPS
GitHub Pages provides free SSL (HTTPS) automatically. Make sure your site is accessible via https://
for better security and SEO rankings.
6. Optimize Your Assets
Compress images, minify CSS/JS, and keep your site lightweight. Faster loading times improve the user experience and search engine performance.
7. Keep Your Site Updated
Regularly commit updates to your site. Since GitHub Pages automatically redeploys when you push changes, your site will always stay fresh and up to date.
Common Issues and Fixes
Even though GitHub Pages is simple to set up, you might run into a few hiccups along the way. Here are some of the most common problems—and how to solve them quickly:
1. My site isn’t loading or shows a 404 error
Cause: Your repository might not be set up correctly.
Fix:
-
Make sure your repo is public.
-
Double-check that GitHub Pages is enabled under Settings → Pages.
-
If you’re using the
username.github.io
format, ensure the repo name is exactly that.
2. Wrong branch or folder selected
Cause: GitHub Pages can only publish from the branch and folder you specify.
Fix:
-
Go to Settings → Pages and ensure the Source is set to the correct branch (usually
main)
and root folder. -
If your site is inside a
/docs
folder, select that folder instead.
3. Custom domain isn’t working
Cause: DNS settings or CNAME file may be incorrect.
Fix:
-
Add a CNAME file to your repo with your domain name (e.g.,
www.mywebsite.com
). -
Update your domain’s DNS records to point to GitHub Pages’ servers.
-
Wait for DNS propagation (can take up to 24–48 hours).
4. The old version of my site is showing
Cause: Browser caching may be showing outdated files.
Fix:
-
Hard refresh your browser (Ctrl+Shift+R on Windows / Cmd+Shift+R on Mac).
-
Try viewing in an incognito window.
5. GitHub Pages shows a “build error”
Cause: Usually related to Jekyll or unsupported file configurations.
Fix:
-
Check the Actions or Pages build logs in GitHub to see the exact error.
By keeping these fixes in mind, you’ll be able to troubleshoot most GitHub Pages issues and keep your site running smoothly.
Conclusion
Hosting a website doesn’t have to cost a fortune or anything at all. With GitHub Pages, you can take your static website live for free, using just a GitHub account and a few simple steps. From creating a repository to enabling Pages and even adding a custom domain, GitHub Pages offers a fast, reliable, and developer-friendly way to showcase your work online.
Whether you’re building a portfolio, resume, blog, or project site, GitHub Pages is an ideal starting point. Now that you know how to set it up, nothing is stopping you from publishing your first site today and sharing it with the world.