Skip to content

Instantly share code, notes, and snippets.

@TylerFisher
Last active December 6, 2023 17:50
Star You must be signed in to star a gist
Embed
What would you like to do?
Basic steps for hosting on Github

Hey there, apparently people are still using this Gist from 2013! It's out of date! Consult the Github docs.

Steps for Hosting a Website on GitHub

  1. Create a GitHub account on github.com.
  2. Download either GitHub for Mac or GitHub for Windows, depending on your operating system. Open the app and log in using the account you just created.
  3. (On Mac): After you login, click advanced and make sure that your name and email are correct. Then, click "Install Command Line Tools", just in case you want to start using the command line later in life.
  4. Create a new repository in your GitHub application. Name it your-username.github.io. The name is very important. Note the folder that GitHub is saving the repository to. Make sure the "Push to GitHub?" box is checked.
  5. Move your website's files into the folder that GitHub just created when you made the repository. IMPORTANT: Your homepage HTML file must be called "index.html", and it must exist in the top-level directory.
  6. Back in the GitHub application, you should see your files in the left column. Make sure they are all checked. If so, enter a message in the text box called "commit summary", something like "initial commit." Then, click the commit button.
  7. Click the "Publish repo" button in the top right corner.
  8. Give it about 10 minutes, then check your-username.github.io. Your website should be there!

Using a custom domain name

You can just leave your website at that address (it'll give you some serious street cred in the developer world), but if you have a custom domain you would like to use, it is very simple to make GitHub redirect your page.

  1. Log in to your domain registrar and find where to change your host records. If you don't know, you can usually Google "(domain registrar) change host records", and your registrar will have an explainer telling you how to do it.
  2. Change your domain's A Record to 204.232.175.78. This is GitHub's IP address, which allows GitHub to resolve your URL and serve the correct files.
  3. In your website's directory folder on your computer, create a file called "CNAME". On the first line, type your domain name. Save the file.
  4. In your GitHub application, you should see the file in the left column. Make sure it is checked and enter your commit message. Have it say something like "Adding CNAME file."
  5. Click "Sync branches."

It can take as long as 48 hours for your domain to resolve to your GitHub page. However, it is usually pretty quick, so check back in an hour or so.

@sagnik1511
Copy link

For the backend part of my code to work, index.html needs to be in a subfolder instead of the root directory. Is there a way to host the website in this case?

You just need to specify the path then like https://{user_name}.github.io/{folder_location_of_index.html}/

Thanks! If I were to use a custom domain, would the path then be https://{custom_domain}/{folder_location_of_index.html}/?

I guess that would be appropriate in general.

@yxuansu
Copy link

yxuansu commented Nov 13, 2021

Super helpful! Big thanks!

@dhiraj80
Copy link

thanks

@labeveryday
Copy link

You rock!

@glennhefley
Copy link

Sweet! Thank you so much

@BARBARBoyyHD
Copy link

my page keep appearing 404 i have already followed everystep but still 404 what the fk is going on ??

@kernel52
Copy link

@BARBARBoyyHD you might want to share some extra info about your issue. even maybe start a new thread?

I'll go from the start assuming nothing and you can tell me how far you've reached down the process

Have you read the guides?

Assuming you created one, what is the name of your repository you try to publish online? [repo_name]

From above you can see the two basic debug steps.
Are the pages option activated?
Is the repo you created public?

To begin with the webpages, maybe you can start first by creating a README.md file on the root folder of your repo.
You should be able to see it using a link constructed as follows https://{user_name}.github.io/{repo_name}/

In your case it should be something like https://BARBARBoyyHD.github.io/{repo_name}/

Give it a try and provide feedback and info.
And give it some time, as there is always some delay in pages and changes appearing.

Caching is good but needs patience when updating content.

@Keshera
Copy link

Keshera commented Mar 12, 2022

I got it to work after selecting a 'Source' from the GitHub Pages (Settings - Pages - Source). Once you select the source, the URL for your website will automatically appear on Settings - Pages.

@cryptogalaxy07
Copy link

Hello stop discussing.

@manu223
Copy link

manu223 commented Mar 31, 2022 via email

@icud
Copy link

icud commented Apr 24, 2022

Can you share how to..

I'm currently using a mobile phone.

@manu223
Copy link

manu223 commented Apr 24, 2022 via email

@SlothCity
Copy link

I get a deprecatedipaddress error when I use that IP address in an A record under google domains. Can anyone help?

@Dishu1234567
Copy link

Say I want to host 2 websites and if I name both of them as [username].github.io and both html files have name index then won't we run into problems. Please someone write a comment about this issue.

@RobyRew
Copy link

RobyRew commented Aug 27, 2022

For the backend part of my code to work, index.html needs to be in a subfolder instead of the root directory. Is there a way to host the website in this case?

Just create a small index on fisrst folder to redirect to your real index.html

@Abdullahitajuddeen
Copy link

can i host php code and its database inside

Copy link

ghost commented Dec 2, 2022

Dont Understand. crap

@Aayush1428
Copy link

When I am putting my php, sql as well as css files on gihub repository and deploying it and when going to my website there on the first page when I click on any option button, it is not entering into that instead it is downloading that code file. What is the problem with it. Suggest me the solution for this problem.

@silvereengames
Copy link

silvereengames commented Mar 4, 2023

how do i create an index page on github, pls. help

in your GitHub repo, create a index.html file and put some html in it.
here is a example to get started:

<head land="en">
  <head>
    <title>New page!</title>
    <meta name="viewport" content="width=device-width, ititial-scale=1.0">
  </head>
  <body>
    <h1>Very cool page</h1>
    <p>Hello world!</p>
  </body>
</html>

@iEddyghost
Copy link

in your GitHub repo, create a index.html file and put some html in it.
here is a example to get started:

`

<title>New page!</title>

Very cool page

Hello world!

`

@Totybeca
Copy link

Thank you for this. it actually worked, but i have an issue, since it can only take index.html files, I have other files linked to the index.html file for my website. How do i add other files apart from index.html?

@Mhaykuce
Copy link

Mhaykuce commented Apr 1, 2023

my page keep appearing 404 i have already followed everystep but still 404 what the fk is going on ??

Same here oo

@RobyRew
Copy link

RobyRew commented Apr 1, 2023

this works perfectly
https://github.com/RobyRew/repo.robyrew.com

I've done this and works literally perfectly.
https://repo.robyrew.com

A bad page IK but its working -_-

@oktaviannikky
Copy link

Hello, I have some issues regarding the hosting, I have done exactly like the tutorial or the guide said. But when I tried to open the website, the 404 error appear.
My website: https://oktaviannikky.github.io/
My repo site: https://github.com/TryHard-777/Oktaviannikky.github.io
What might be the issues, please

@RobyRew
Copy link

RobyRew commented May 16, 2023

My website: https://oktaviannikky.github.io/
My repo site: https://github.com/TryHard-777/Oktaviannikky.github.io

your repository has Caps your website doesn't.

@oktaviannikky
Copy link

My website: https://oktaviannikky.github.io/
My repo site: https://github.com/TryHard-777/Oktaviannikky.github.io

your repository has Caps your website doesn't.

Already change the caps lock (if that what u mean), but still can not connect to my website.
When I tried looking for error in the action section, there is something like this:
image

What should I do, Please help

@Munyalo328
Copy link

How can I get the url for my repository?

@oktaviannikky
Copy link

How can I get the url for my repository?

if u mean ur webpage url then ur repo name is the url
image

but if u mean the repo link like "https://github.com/TryHard-777/Oktaviannikky.github.io"
u can just open ur repo then copy the url

@Hermon71type
Copy link

Can I just make web pages without JS
Im a beginner Web developer

@iEddyghost
Copy link

iEddyghost commented Oct 25, 2023 via email

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