Have you ever created a website using HTML, CSS, JavaScript, or React and wondered how to make it accessible to everyone on the internet?
You don’t necessarily need to purchase hosting or a server to publish your website. GitHub Pages allows you to host and deploy static websites for free.
In this blog, we’ll understand how to deploy a website using GitHub Pages, from creating a repository to accessing your live website.
1. What Is GitHub Pages?
GitHub Pages is a free hosting service provided by GitHub that allows developers to publish static websites directly from a GitHub repository.
You can use it to host:
- Personal portfolios
- Freelancing websites
- Landing pages
- Documentation websites
- HTML, CSS, and JavaScript projects
- Project demonstrations
For example, your website can be published at:
2. Prerequisites
Before deploying your website, make sure you have:
- A GitHub account.
- A website project created using HTML, CSS, and JavaScript.
- Your project files ready.
- A web browser and internet connection.
Example project structure:
my-website/
│
├── index.html
├── style.css
├── script.js
└── images/
└── banner.png
Make sure your main HTML file is named index.html.
3. Create a GitHub Repository
First, visit GitHub and log in to your account.
Follow these steps:
- Click the New Repository button.
- Enter your repository name, such as
my-website. - Select Public visibility (or check your plan’s Pages access for private repositories).
- Click Create Repository.
Your repository is now ready.
4. Upload Your Website Files
Now upload your website project files to GitHub.
- Open your newly created repository.
- Click Add file.
- Select Upload files.
- Drag and drop your HTML, CSS, JavaScript, and image files.
- Click Commit changes.
Your website source code is now available in your GitHub repository.
Alternatively, you can push your project using Git commands:
git init
git add .
git commit -m "Initial website upload"
git branch -M main
git remote add origin https://github.com/USERNAME/my-website.git
git push -u origin main
Replace USERNAME with your GitHub username.
5. Enable GitHub Pages
This is the most important step.
- Open your GitHub repository.
- Navigate to Settings.
- Find Pages in the left sidebar.
- Under Build and deployment, select Deploy from a branch.
- Select the
mainbranch. - Select the
/ (root)folder. - Click Save.
GitHub will automatically start deploying your website.
6. Access Your Live Website
After the deployment process is complete, visit the Pages section in your repository.
GitHub will provide a live website URL similar to:
Congratulations! Your website is now live on the internet.
7. How to Update Your Website?
One of the best features of GitHub Pages is automatic deployment.
Whenever you make changes to your website, upload the updated files or push your changes using Git:
git add .
git commit -m "Updated website design"
git push origin main
GitHub Pages will automatically rebuild and publish your updated website.
8. Can You Connect a Custom Domain?
Yes! You can connect your own domain name, such as:
www.yourwebsite.com
To do this:
- Purchase a domain from a domain registrar.
- Open your repository’s Settings → Pages.
- Enter your custom domain.
- Configure the required DNS records with your domain provider.
- Enable HTTPS once DNS verification is complete.
Your website can now be accessed using your custom domain.
9. Important Limitations of GitHub Pages
Although GitHub Pages is an excellent free hosting solution, there are some limitations.
- It is designed for static websites.
- It does not directly support backend execution such as PHP, Python, or Node.js.
- It does not provide a built-in database.
- It is not intended for e-commerce applications requiring server-side processing.
- GitHub Pages has published usage limits, so it is not designed for every production workload.
For full-stack applications, you can consider platforms such as Vercel, Netlify, or Render.
10. Conclusion
Deploying a website using GitHub Pages is one of the easiest ways for beginners, students, and freelancers to publish their projects online without paying for traditional web hosting.
If you’re learning web development or building your freelancing portfolio, start deploying your projects using GitHub Pages.
Remember: Building a website is just the first step. Making it accessible to the world is what completes the process!
Happy Coding! 🚀
Leave a Reply