How to publish your GitHub pages on a domain

Photo by Igor Miske on Unsplash

Publishing your GitHub pages is a two step process: you first configure GitHub and then set the DNS.

On GitHub

Assuming that you already pushed the website to GitHub, go to “Settings”.If you already didn’t so, rename your repository as <mysite>.github.io: this will publish your repository as <mysite>.github.io.

Now scroll down to find the “GitHub Pages” section. Publish the master branch:

Enabling HTTPS is not mandatory but is strongly suggested.

Specify your custom domain:

Now it’s time to create a special file in the root directory of the site repository, the CNAME file:

This file contains only one text row, specifying the pointing domain:

mysite.com

On DNS management

Before making changes, backup your current DNS configuration.

In your DNS management interface (I will refer to Aruba provider), add the following A records (as stated in this help page on GitHub), without specifying an host name:

185.199.108.153
185.199.109.153
185.199.110.153
185.199.111.153

If the www host is defined in A record, remove it, because you are going to add it as CNAME record.

Now on with CNAME records. Add a www host, pointing to <mysite>.github.io. (replace <mysite> with the real name of your repository name): don’t forget to add the dot (.) at the end of the hostname!

If everything is ok, you should see a green banner in the Setting section of the published repository.

Please allow some hour to DNS to propagate and enjoy your website!

Bonus track: adding a subdomain

You can publish a subdomain like blog.mysite.com, creating and publishing another repository on GitHub with a CNAME file specifying the subdomain name in its content:

blog.mysite.com

In your DNS management interface, create another CNAME record with “blog” as hostname and pointing again to <mysite>.github.io. (dot included!)

GitHub will take care to publish the correct repository on the corresponding subdomain.

--

--

--

Full-time Human-computer interpreter. Opinions are my own.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Organize your Project with Dat

Hibernate: Don’t use show_sql to log SQL queries

My Takeaway from the Twilio’s Founders Book ASK YOUR DEVELOPER

Writing Triumph over Time

Data 360 Approach — The North Star of Divine Data Experience and Personalization

How to make github CLI works with SSH URLs within https login

Google Cloud Platform(GCP): Using Compute Engine and Google Map API to build a website that can…

Implementing Microservice in Red Hat OpenShift Container Platform

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Juna Salviati

Juna Salviati

Full-time Human-computer interpreter. Opinions are my own.

More from Medium

Importing 4-byte unicode characters to MySQL at command line

How to store uploaded files in the S3 bucket when using elastic beanstalk PHP App

API? What?

How to install an SSL certificate on Alpha Five?