How to Deploy an Existing Public Repository with GitHub Pages
Already have a project in a public GitHub repository? This guide will show you how to quickly publish it as a live website using GitHub Pages. It’s a free and powerful way to host your static websites (HTML, CSS, JavaScript).
Step 1: Prerequisites - Check Your Repository
Before you start, make sure you have the following set up:
-
A Public GitHub Repository: The project you want to deploy must already exist in a public repository on your GitHub account. GitHub Pages for free accounts only works with public repos.
-
An
index.htmlfile: Your repository must contain anindex.htmlfile in the main (root) directory. This is the file that will be shown as your homepage.
If your project is missing an
index.htmlfile, you can easily add one directly on GitHub by navigating to your repository and clickingAdd file > Create new file.
Step 2: Activate GitHub Pages in Your Repository Settings
This is where you tell GitHub to turn your code into a live website.
- Go to the main page of your existing public repository on GitHub.
- Click the “Settings” tab in the navigation bar (next to “Code”, “Issues”, etc.).
- In the left sidebar of the Settings page, click on “Pages”.
- Under the “Build and deployment” section, ensure the Source is set to “Deploy from a branch”. This is usually the default.
- Under the Branch section, select
main(ormasterif that’s the name of your primary branch) from the dropdown menu. Leave the folder as/ (root). - Click the “Save” button.
Step 3: Visit Your Live Website!
You’re done! Now you just have to wait a moment for GitHub to work its magic.
- After you click “Save”, the page will refresh. It can take 1-2 minutes for GitHub to build and deploy your site for the first time.
- After waiting a minute, refresh the “Pages” settings page again. At the top, you will see a green or blue box with a message saying: “Your site is live at [your new URL]”.
- Click the link to see your website live on the internet!
The URL will be in the format: https://your-username.github.io/your-repository-name/
How to Update Your Website
Updating your site is incredibly simple. Any time you push new changes (or upload new files) to your main branch, GitHub Pages will automatically see the changes, rebuild your site, and publish the updates. The changes will appear at the same URL within a few minutes.