How to Publish a Static Website on GitHub?
Last Updated :
19 Jun, 2024
Publishing a static website on GitHub is a great way to share your work with the world. GitHub Pages is a service offered by GitHub that allows you to host your static websites directly from a GitHub repository. In this article, we’ll walk you through the steps to publish your static website on GitHub.

Hosting a website enables many web users to access our web pages at the same time. If you want to run a website you need web hosting because unless you’ve got unlimited funds you would not be able to afford the web servers. GitHub has a lot to offer, it provides free hosting to your static website. To host the website via GitHub you’ll require a valid git account, the git software, and all the codes and files of your static website.
How to Publish a Static Website on GitHub: Step-by-Step Guide
Step 1: Create / Sign into your GitHub account.
- Go to https://github.com/ and create a new account if you don’t have one already.
- If you already have an account, sign in using your username and password.
Check Out: How to Install GIT on Windows, MacOS and Linux?

Check Out: An Ultimate Guide to Git and Github
Step 2: Create a New Public Repository
- Click on the “+” button in the top right corner and select “New repository“.
- Give your repository a descriptive name (all lowercase letters, underscores, hyphens are allowed). This name will be used in the website URL later.
- Under “Visibility“, select “Public” to allow your website to be accessible by everyone.
- Click “Create repository” to create your new repository.
Note : Please keep this Repository name handy we will require Repository Name while adding remote for pushing our code.

Step 3: Prepare Your Website Files
- Make sure you have all your website’s files ready, including HTML, CSS, JavaScript, and any images or other assets.
- Organize your files in a way that makes sense for your website structure. Typically, your main HTML file will be named “index.html”.
- Navigate to the directory on your computer where your website files are stored. Right-click anywhere within your website directory.
- Select “Git Bash Here” from the context menu. This will launch a Git Bash window specific to your current directory.

Step 4: Initialize a Git Repository in Your Website Directory
- Navigate to the directory on your computer where your website files are stored.
- In the git bash, type
git init and press Enter. This command initializes a new Git repository in your current directory.

Step 5: Add All Files to the Git Repository
In the GitBash Window, type git add . and press Enter. The dot (“.”) tells Git to add all files in the current directory to the repository.

Step 6: Check the Status of the Repository (Optional)
Now check the status of the repository by giving the command “git status“, if all the files are in green means the files are successfully stored in the repository.

Step 7: Commit Your Changes with a Message
In the Git bash, type git commit -m "first commit" and press Enter.
Replace “first commit” with a more descriptive message that summarizes the changes you’re committing. This message will be helpful for tracking changes later.

Step 8: Add the Remote Repository (GitHub) URL
In the Git bash, type the following command, replacing {yourGithubUserName} with your actual GitHub username and {repoName} with the name of your repository you created in Step 2:
git remote add origin https://github.com/{yourGithubUserName}/{repoName}.git
Press Enter. This command adds a remote repository called “origin” which points to your GitHub repository.

Step 9: Push Your Code to GitHub
- In the Gitbash Window, type
git push -u origin master and press Enter.
- You will be prompted to enter your GitHub username and password.
- This command pushes your local Git repository (with your website files) to the remote repository on GitHub.

Step 10: Configure GitHub Pages (Optional for Static Websites)
Go to the GitHub page, click on your project and you can see all the files are pushed in the repository. Go to the setting and find GitHub Pages, in the source section from the drop-down menu select master branch save the changes. And your Site is successfully published, copy the url and open it in the new tab.

Step 11: Access Your Published Website
- After a few minutes, GitHub Pages will process your website files and make them publicly accessible.
- You can access your website by going to the following URL:
https://{yourGithubUserName}.github.io/{repoName}
- Replace
{yourGithubUserName} with your GitHub username and {repoName} with the name of your repository.

Must Read:
Conclusion
In conclusion, hosting your static website on GitHub Pages is a fantastic way to get your project online quickly and easily. It’s completely free, requires minimal technical knowledge, and offers built-in version control for easy management. By following these steps, you’ll have your website up and running in no time, ready to impress the world with your creativity and expertise.
For an extra dose of customization, explore the vast amount of free static site generators available online. These tools can streamline your workflow and empower you to create stunning websites without needing to write tons of code. With GitHub Pages and a static site generator at your fingertips, the possibilities for your online presence are limitless!
How to Publish a Static Website on GitHub – FAQs
Is GitHub Pages secure for hosting my website?
Yes, GitHub Pages offers a secure and reliable platform for hosting static websites. Your files are stored on GitHub’s servers, which benefit from industry-standard security practices. For more advanced security needs, however, you might consider paid web hosting options.
What are the advantages of using GitHub Pages for static websites?
There are several advantages to using GitHub Pages for static websites:
- Free Hosting: It eliminates the cost of web hosting, making it a budget-friendly option for individuals and startups.
- Version Control: Built-in Git version control allows you to track changes, revert to previous versions, and collaborate easily with others.
- Simplicity: Getting started is straightforward, especially for those already familiar with Git.
- Scalability: GitHub Pages can handle a significant amount of traffic, making it suitable for growing websites.
What type of websites are best suited for GitHub Pages?
GitHub Pages is ideal for hosting static websites. These websites consist of HTML, CSS, and JavaScript files, and don’t require server-side scripting languages like PHP. Examples include:
- Portfolios
- Blogs
- Landing pages
- Documentation websites
Can I use a custom domain name with GitHub Pages?
Yes, you can use a custom domain name with GitHub Pages to give your website a more professional look. You’ll need to configure your domain name provider to point to your GitHub Pages website.
Similar Reads
How to Publish a Static Website on GitHub?
Publishing a static website on GitHub is a great way to share your work with the world. GitHub Pages is a service offered by GitHub that allows you to host your static websites directly from a GitHub repository. In this article, we’ll walk you through the steps to publish your static website on GitH
6 min read
Using GitHub to Host a Free Static Website
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 usi
3 min read
How to Deploy Your React Websites on GitHub?
Building a web application is always exciting for developers especially when you step into the programming world for the first time. You build the front end of your application after a lot of struggle and you want to showcase your skill, your creativity, and of course your hard work to the world. So
6 min read
How to create a website in React JS ?
React JS is an open-source, component-based front-end library responsible only for the view layer of the application. It is maintained by Facebook. React uses a declarative paradigm that makes it easier to reason about your application and aims to be both efficient and flexible. It designs simple vi
5 min read
How to Build Portfolio Website And Host It on GitHub Pages?
Having an online portfolio is important for showcasing your skills and accomplishments. GitHub Pages provides a convenient and free platform for hosting your portfolio website. In this article, we will see how to build a Portfolio Website And Host It on GitHub Pages. Table of Content Creating a Port
15 min read
How to Host a Website on GitHub For Free?
It is very important to have an online presence if you are an individuals or having a businesses. Fortunately platforms like GitHub provides the facility to host a website for free. In this article, we will see How to Host a Website on GitHub For Free. Basic Steps for Hosting Website on GitHubHere,
5 min read
How to Deploy a Basic Static HTML Website to Heroku?
Heroku is a simple and one-stop solution to host any website or server. This article revolves around how you can host your own Static HTML webpage on Heroku. To demonstrate this we are going to build a simple webpage and host it. PrerequisitesGitHeroku AccountHeroku CLI Let's create a directory name
3 min read
How to Link GitHub with Visual Studio?
Linking GitHub with Visual Studio allows you to manage your code repositories, collaborate with others, and streamline your development workflow directly from your IDE. Visual Studio provides integrated tools for cloning, creating, and managing GitHub repositories. Prerequisite:Visual Studio install
1 min read
How To Publish Your Website On Wordpress?
Publishing a website using WordPress has become a popular choice for individuals and businesses looking to establish an online presence. WordPress offers an easy-to-use platform with customizable features that cater to a variety of needs. This article will describe the steps needed to successfully p
3 min read
How to Push Code to Github using Pycharm?
Git is an open-source version control system. It means that whenever a developer develops some project (like an app or website) or something, he/she constantly updates it catering to the demands of users, technology, and whatsoever it maybe, Git is a version control system that lets you manage and k
2 min read
How To Create a Pull Request in GitHub?
Pull requests are an important part of collaborative software development on GitHub. They allow developers to propose changes, review code, and discuss improvements before integrating new code into a project. This guide will walk you through the process of creating a pull request in GitHub, ensuring
2 min read
How to Add Code on GitHub Repository?
GitHub is a powerful platform for hosting and sharing code. Whether you’re working on a solo project or collaborating with others, adding code to a GitHub repository is essential. Here’s a step-by-step guide on how to add your code to a GitHub repository. Steps to Add Code on GitHub RepositoryStep 1
2 min read
How to Add Github to Linkedin?
Adding a GitHub profile to LinkedIn is a great way to showcase our coding projects, contributions, and technical skills. This can enhance our LinkedIn profile by providing potential employers and professional connections with direct access to our work. There are multiple ways to add your GitHub to L
2 min read
How to Create a Pull Request on GitHub using Android Studio?
Creating a pull request is an important part of collaborating on projects hosted on GitHub. It allows you to propose changes to a repository, enabling others to review, discuss, and merge your changes. Here’s a step-by-step guide on how to create a pull request on GitHub using Android Studio. Steps
2 min read
How To Push A Big Next.js App To GitHub?
Managing a big Next.js and version control of the deployed Next. js application could be challenging sometimes, especially when it comes to file size and repository issues. This guide will help you no matter if you are an experienced programmer or a person who never used GitHub at all. It explains h
3 min read
How to Create Pull Request on GitHub Without Using any IDE?
Creating a pull request (PR) on GitHub is an important part of collaborative software development. It allows you to propose changes to a project, which can then be reviewed and merged by other contributors. You don't need an Integrated Development Environment (IDE) to create a pull request. In this
1 min read
How To Upload a Project On GitHub?
Uploading your project to GitHub allows you to share your work with others, collaborate with team members, and keep your code safe and accessible. This article will walk you through the process of uploading a project to GitHub, ensuring that you can efficiently manage your code and contributions. Pr
4 min read
How to create static front page in WordPress ?
Creating a static front page in WordPress can give your website a professional and customized look. Unlike the default setting where your latest posts are displayed on the homepage, a static front page allows you to showcase specific content that remains constant. This is particularly useful for bus
4 min read
How to Update or Sync a Forked Repository on GitHub?
When you fork a repository on GitHub, you basically make a copy of the original repository and keep it under your own account. As time goes on, the original repository (known as the "upstream" repository) might receive updates, and it's important to keep your fork up to date with these changes. This
2 min read