DEV Community ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ป

DEV Community ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ป is a community of 964,423 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Cristal
Cristal

Posted on

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!

Top comments (2)

Collapse
 
felipperegazio profile image
Felippe Regazio • Edited on

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

Collapse
 
cristalcodes profile image
Cristal Author

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 :)

๐ŸŒš Life is too short to browse without dark mode