Skip to content

Instantly share code, notes, and snippets.

@jsoma
Last active November 13, 2022 07:15
Show Gist options
  • Save jsoma/47c55318916021180b1aee3f37c7b4c2 to your computer and use it in GitHub Desktop.
Save jsoma/47c55318916021180b1aee3f37c7b4c2 to your computer and use it in GitHub Desktop.
Publishing your site on GitHub Pages

Hosting your site on GitHub Pages

We're going to start by creating a new repository using GitHub Pages.

Create a new repository

And we're going to name is after ourselves! My github username is jsoma, so I'm going to call my repository jsoma.gitub.io.

Name your repository YOURUSERNAME.github.io. Double-check what your GitHub username is. If you do this part wrong, you'll be sad!

New repository options

Now you'll have a new folder created, called jsoma.github.io, and that's where we're going to put our project website data.

Naming and organizing our files

No matter how many HTML files we have - maybe we'll end up with a thousand projects - every single HTML file needs to be called index.html.

...but why?

Eventually we'll visit the URL https://jsoma.github.io/, and our index.html shows up, even though we didn't explicitly ask for it. That's web server magic - when we ask for a web page from the domain, it will try to find a file called index.html and send it back to us.

If we asked for cats.html, though, it would try to find that exact file to send it back to us. But... no one likes to type https://jsoma.github.io/cats.html! People would much rather rather type https://jsoma.github.io/cats/, because it's nice and pretty.

So what we do is always name our files index.html. If we have a different project - like "cats," for example - we put that file in a subdirectory called /cats.

We ask for We are given
jsoma.github.io jsoma.github.io/index.html
jsoma.github.io/cats/cats.html jsoma.github.io/cats/cats.html
jsoma.github.io/cats/ jsoma.github.io/cats/index.html
jsoma.github.io/cats.html jsoma.github.io/cats.html

As a result...

  • You'll have an index.html as your homepage for the entire portfolio.
  • Each project will get a folder (lie cats)
  • Each folder will have an index.html in it

For now I think you can focus on putting a single project in a single folder.

So now, do that. Put your files in the right place. Mine looks like this:

File organization

Pushing up to GitHub

Now you'll need to use GitHub Desktop to commit and send everything up.

Commits

If you're on OS X: don't commit .DS_Store! Even better: add a .gitignore file to ignore it. But if you accidentally add it, no big deal.

When you're done with your commits, you'll want to push up to GitHub. Be sure you uncheck the private repository box. You want everyone to be able to see your website, right?

Push up to github

Visiting our site

Now that our site is pushed up, we'll give GitHub a little while to set things up, and we'll be able to visit it! Just go to whatever your repository name is - mine was jsoma.github.io and so I'll go ahead and visit jsoma.github.io. Works like magic!

If it doesn't work for you, chances are you either put your work into a subdirectory or you didn't name your repository correctly. Double-check!

@arthurabia
Copy link

Hi, I was looking for a quick explanation of the "index.html" thing, and you helped me more than anyone on the Internet, so thanks a lot !!!

@itsshalag
Copy link

Came from the odin project and really thought "why do we have to have an index.html?" thank you for your help!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment