When using GitHub Pages, it looks for an index.html file as the homepage. If your repository doesn't have index.html, your website may not load properly. Below are solutions to fix this issue.
If your repository has a file like demo.html, but GitHub Pages is not working, rename it to index.html using Git.
-
Rename the File Using Git Command:
git mv demo.html index.html
-
Commit the Changes:
git commit -m "Renamed demo.html to index.html" -
Push the Changes to GitHub:
git push origin main
-
Check Your GitHub Pages Link:
Now, visit your GitHub Pages link:https://<your-username>.github.io/<repository-name>/Your website should load properly with
index.htmlas the main page.
You can store your HTML file inside a folder (like docs) and set GitHub Pages to use that folder.
-
Create a Folder and Move Your HTML File:
mkdir docs mv index.html docs/
-
Commit and Push the Changes:
git add . git commit -m "Moved index.html to docs folder" git push origin main
-
Change GitHub Pages Settings:
- Go to Settings in your repository.
- Scroll down to GitHub Pages.
- Under Source, select
docs/folder.
-
Check Your GitHub Pages Link:
https://<your-username>.github.io/<repository-name>/
Now, your website will load the index.html file from the docs folder.
If you don't want to rename your file but still want to access it, you need to manually specify the file name in the URL.
-
Ensure Your File Exists in the Repository
Example: If your file isdemo.html, it should be visible in your repository. -
Access the File Using This URL:
https://<your-username>.github.io/<repository-name>/demo.html
Now, your file will open directly without renaming it.
For React, Angular, Vue, or other built projects, itβs best to use a gh-pages branch.
-
Create a
gh-pagesBranch:git checkout -b gh-pages
-
Commit Your
index.htmlingh-pagesBranch:git add . git commit -m "Set up gh-pages branch with index.html" git push origin gh-pages
-
Enable GitHub Pages for
gh-pagesBranch:- Go to Settings > GitHub Pages.
- Select
gh-pagesas the source.
-
Check Your GitHub Pages Link:
https://<your-username>.github.io/<repository-name>/
Now, your site will load properly.
| Solution | When to Use |
|---|---|
Rename demo.html to index.html |
If GitHub Pages is not loading your file. |
Use docs/ Folder |
If you want a cleaner repo structure. |
| Use a Custom File URL | If you don't want to rename demo.html. |
Use gh-pages Branch |
If working with frameworks like React. |
- Wait a few minutes β sometimes it takes time to update.
- Clear browser cache (
Ctrl + Shift + R). - Make sure your repository is public (GitHub Pages doesn't work for private repos unless you have a Pro account).
- Check GitHub Pages settings to ensure it's enabled.
Now, you're all set to fix GitHub Pages issues! πβ¨