Using GitHub to Host a Free Static Website
Last Updated :
15 May, 2024
Having a personal or project website is important for showcasing your work. Fortunately, GitHub Pages offers a simple and free solution for hosting static websites directly from your GitHub repositories. In this article, we'll walk you through the process of creating and hosting a static website using GitHub Pages.
Prerequisites
What are GitHub Pages?
GitHub Pages is a feature of GitHub that allows users to host static websites directly from their GitHub repositories. Whether you're a developer, designer, or hobbyist, GitHub Pages provides an easy and convenient way to share your projects, portfolios, documentation, or personal blogs with the world.
Steps to Host Website on GitHub
Step 1: Create/ Sign into your GitHub account.
Step 2 Create a new GitHub Repository
Go into your dashboard and find a “New Repository” button. Click on it to create a new repository and name it whatever you want and in description you can give some information about your repository.
Creating a repoStep 3: Now we have to clone this repo on our local system, so for that click on the code and copy the url of this repository.
Clone Repo
Step 4: Now open git bash or any terminal in system, make sure that git is already installed and configured properly. Now write the command for cloning the repository this will create a folder on your local system with the same name as of your Github Repository.
git clone "url of repo that you have copied"
Cloning a Git repoNow go inside this folder, here you have to create your webpage or a whole website, lets make a simple webpage here and host it on Github.
Make a index.html file and write "Hello World this is my first web page." like this
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>GFG</title>
</head>
<body>
<h1>Hello World this is my first web page.</h1>
</body>
</html>
Basic Static WebsiteStep 5: Now run some basic commands and push this file to Github.
git add -A
git commit -a -m "first commit"
git push origin master
Push files to GitHubNow the webpage is pushed to Github you can see this index.html file in your repository, now we are good to go to host our webpage.
Files of repositoryStep 6: Now just follow these steps carefully.
- Go to setting and scroll down to Github pages
- Click on "check it out here"
- Click on the dropdown currently showing none and select your branch in our case it is master.
- Click on save, you can see a url on the top of it in the format of https://<username>.github.io/<repo name>. This is url of your hosted webpage.
Hosting on GitHub PagesCongratulations you have hosted your first web page successfully for free.
Hosted Website
Similar Reads
Frontend Developer Interview Questions and Answers Frontend development is an important part of web applications, and it is used to build dynamic and user-friendly web applications with an interactive user interface (UI). Many companies are hiring skilled Frontend developers with expertise in HTML, CSS, JavaScript, and modern frameworks and librarie
15+ min read
Git Tutorial Git is an essential tool for developers, enabling them to manage and track project changes. Whether you're working on a solo project or collaborating with a team, Git keeps everything organized and under control. This Git Tutorial, from beginner to advanced, will give you a complete understanding of
12 min read
Git Cheat Sheet Git Cheat Sheet is a comprehensive quick guide for learning Git concepts, from very basic to advanced levels. By this Git Cheat Sheet, our aim is to provide a handy reference tool for both beginners and experienced developers/DevOps engineers. This Git Cheat Sheet not only makes it easier for newcom
10 min read
Git Rebase Git Rebase is a command that moves or combines a sequence of commits to a new base commit. It helps you place your changes on top of another commit, resulting in a cleaner, linear history, especially useful when working with feature branches. Unlike git merge, which creates a merge commit to combine
10 min read
Version Control Systems Version Control Systems (VCS) are essential tools used in software development and collaborative projects to track and manage changes to code, documents, and other files. Whether you're working alone or as part of a team, version control helps ensure that your work is safe, organized, and easy to co
7 min read
Git Bash Git bash is a command-line tool that is used as Git CLI emulation for Microsoft Windows. It provides a terminal-like interface and enables users to run Git commands and interact with a repository, as well as offering Unix command line features. Essentially, Git Bash brings the powerful functionaliti
9 min read
How to Create a New Branch in Git? Git is a powerful and widely used version control system that helps developers manage code changes across projects efficiently. One of the fundamental features of Git is branching, which allows developers to diverge from the main line of development and work on different tasks or features independen
4 min read
50+ Essential Git Commands for Beginners and Developers Git is a powerful version control system that helps developers track changes, collaborate seamlessly, and manage codebases efficiently. Whether you're working on a solo project or collaborating with a team, Git ensures your work is safe, versioned, and organized. So weâll explore 50+ essential Git c
7 min read
How to Set Git Username and Password in GitBash? Setting up your Git username and password is an essential step when working with Git repositories. It helps you confirm your identity when sending (pushing) changes or getting (pulling) updates from a remote repository. In this guide, we will show you how to easily set your Git username and password
3 min read
How To Get Changes From Master Into a Branch in Git? In Git, branches are essential for organizing and managing development work. Whether you are working on a feature, a bug fix, or any other task, you often work in a separate branch so that the changes donât directly affect the master or main branch (the primary production branch).There are two main
3 min read