DEV Community

Cristal
Cristal

Posted on

10 2

Hosting on Github Pages: A Quick and Short How To

So you have a website that only uses HTML, CSS, & JS? What an exciting time to be alive, you can host your site straight to Github without spending a dime!

The main benefit is that you don't have to worry about buying a domain name and setting up your hosting site. If you've pushed your project up to Github, you've already done the bulk of the work!

Ready to see how easy this is?

1. Create a new branch

In your terminal (command line), cd your way into your project directory (folder). Once there, create a new branch by running the following command:

git checkout -b gh-pages 
Enter fullscreen mode Exit fullscreen mode

You must name your branch gh-pages in order for this to work correctly.

2. Push to origin

Next, run the following command:

git push origin gh-pages
Enter fullscreen mode Exit fullscreen mode

3. Verify it worked!

Go to your repo on Github and click on the 'Branch' dropdown. You should see gh-pages there now!

Alt Text

4. Visit your site

In your browser, head over to:

your-user-name.github.io/repo-name
Enter fullscreen mode Exit fullscreen mode

Et voila! Your site!

Happy Coding!

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (2)

Collapse
 
felipperegazio profile image
Felippe Regazio • Edited

Wow, i didnt knew about gh-pages branch, i was publishing from ./docs or even root. Thanks!

Collapse
 
cristalcodes profile image
Cristal

I'm so glad this is useful to you! I just learned about it myself and had to document it to always have a reference :)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay