Github Pages: Index HTML Not in Root

Ann Jul 09, 2026

When setting up a GitHub Pages site, you might encounter an issue where your index.html file isn't located in the root directory. This can lead to a 404 Not Found error, as GitHub Pages expects the index.html file to be in the root of your repository or the specified branch. Let's delve into this issue, understand why it happens, and explore solutions to resolve it.

git
git

Before we dive into the solutions, let's ensure we're on the same page. GitHub Pages is a static site hosting service that takes HTML, CSS, and JavaScript files straight from a repository on GitHub, and serves them over the web. It's a simple and powerful way to put up a personal website, project portfolio, or even a blog.

two screens showing different types of web pages
two screens showing different types of web pages

Understanding the Index.html Location

GitHub Pages looks for the index.html file in the root directory of your repository or the specified branch. If it's not found there, GitHub Pages will return a 404 Not Found error. This is because GitHub Pages doesn't traverse subdirectories to find your index.html file.

GitHub - ArchiveXVault/readme-generator: Generate readme for github repos
GitHub - ArchiveXVault/readme-generator: Generate readme for github repos

For instance, if your repository structure looks like this:

/my-repo
  /css
    style.css
  /js
    script.js
  /index.html

GitHub Pages will not be able to find the index.html file and will return a 404 error. This is because the index.html file is not in the root directory of the repository.

an image of a web page with the words hi, i'm divyansh chaudhary
an image of a web page with the words hi, i'm divyansh chaudhary

Moving Index.html to the Root Directory

The most straightforward solution is to move your index.html file to the root directory of your repository. This ensures that GitHub Pages can find it and serve your website correctly. Here's how you can do it:

  1. Navigate to your repository on GitHub.
  2. Click on the '+' icon next to the 'Code' button and select 'Create new file'.
  3. Name the file 'index.html' and paste your website's code into it.
  4. Commit the changes with a meaningful commit message.
An Apple-style layout focuses on clarity, spacing, and logical hierarchy, making your content
An Apple-style layout focuses on clarity, spacing, and logical hierarchy, making your content

After doing this, your GitHub Pages site should be up and running without any 404 errors.

Using a Baseurl in Your _config.yml File

If moving your index.html file to the root directory isn't an option, you can use a baseurl in your _config.yml file to tell Jekyll where to find your index.html file. This is particularly useful if you're using Jekyll to generate your static site.

gitFlow
gitFlow

Here's how you can do it:

baseurl: /your-repo-name
url: https://yourusername.github.io

In this example, replace 'your-repo-name' with the name of your repository and 'yourusername' with your GitHub username. This tells Jekyll to look for your site's files in the 'your-repo-name' directory.

Git Vs Github
Git Vs Github
an image of a computer screen with many lines and numbers on it, all in different colors
an image of a computer screen with many lines and numbers on it, all in different colors
an image of a website page with the text'html 5 page for seo '
an image of a website page with the text'html 5 page for seo '
the github chat sheet is displayed in this screenshote screen graber
the github chat sheet is displayed in this screenshote screen graber
Git vs GitHub Explained (Day 24 Git Guide)
Git vs GitHub Explained (Day 24 Git Guide)
a red and black text description for a web page with an arrow pointing to it
a red and black text description for a web page with an arrow pointing to it
Github Cheatsheet
Github Cheatsheet
HTML Basics Made Simple | AinosCodex Web Development Guide
HTML Basics Made Simple | AinosCodex Web Development Guide
a computer screen with an image of mountains and trees in the backgrouds
a computer screen with an image of mountains and trees in the backgrouds
Hands-on: GitHub for Windows takes the pain out of using git
Hands-on: GitHub for Windows takes the pain out of using git
GitHub - buntec/git-summary: git-summary is a command-line tool that displays a concise status summary of all git repos under a given root (which defaults to the current working directory).
GitHub - buntec/git-summary: git-summary is a command-line tool that displays a concise status summary of all git repos under a given root (which defaults to the current working directory).
the bootstrap website homepage
the bootstrap website homepage
an info sheet with different types of font and numbers, including the letter j in red
an info sheet with different types of font and numbers, including the letter j in red
a table with several different types of text and numbers on the top, bottom left corner
a table with several different types of text and numbers on the top, bottom left corner
Top 10 Useful GitHub Repos That Every Developer Should Follow
Top 10 Useful GitHub Repos That Every Developer Should Follow
a black screen with an image of a web development flow chart on it's side
a black screen with an image of a web development flow chart on it's side
the page structure in html5
the page structure in html5
HTML Document Structure
HTML Document Structure
a black background with the words, 7 github repostories to master react
a black background with the words, 7 github repostories to master react
Level Up Your Github Profile Page in Three Easy Steps
Level Up Your Github Profile Page in Three Easy Steps

Specifying a Source Branch

By default, GitHub Pages serves your site from the 'master' branch. If your index.html file is in a different branch, you'll need to specify this branch as the source for your GitHub Pages site.

Here's how you can do it:

  1. Go to your repository on GitHub.
  2. Click on the 'Settings' tab.
  3. Scroll down to the 'GitHub Pages' section.
  4. Under 'Source', select the branch that contains your index.html file.
  5. Click 'Save'.

After doing this, GitHub Pages will serve your site from the specified branch.

Using a Custom Domain

If you're using a custom domain with your GitHub Pages site, you'll need to ensure that your index.html file is in the root directory of your repository or the specified branch. This is because custom domains are served from the root directory of your repository or the specified branch.

Here's how you can ensure this:

  1. Follow the steps in the 'Moving Index.html to the Root Directory' section to move your index.html file to the root directory of your repository.
  2. Go to your repository on GitHub.
  3. Click on the 'Settings' tab.
  4. Scroll down to the 'GitHub Pages' section.
  5. Under 'Custom domain', enter your custom domain name.
  6. Click 'Save'.

After doing this, your custom domain should be serving your site correctly.

In conclusion, ensuring that your index.html file is in the root directory of your repository or the specified branch is crucial for serving your GitHub Pages site correctly. Whether you're using a default branch, a custom domain, or a static site generator like Jekyll, this simple step will ensure that your site is up and running without any 404 errors. Happy coding!