Why use Gitlab Pages instead of Github Pages?
- Gitlab builds HTML using any static site generator, while Github builds only with Jekyll. However, for Github you could build on your laptop with any static generator and push HTML to Github Pages.
- Thus, Gitlab builds with any Jekyll plugin, while Github restricts builds to only white-listed Jekyll plugins (disallowing smart “related posts” for example)
- Gitlab allows custom domains (domain aliases) such as
Note that both Gitlab and Github allow the source files (e.g. Markdown) to be private for a public website. On Github you would have to have a paid subscription to have one or more private repos. You should have a private website repo. Otherwise Google will present search results from your website repo Markdown code instead of or alongside the rendered webpages!
Gitlab Pages quick setup
- create a new Project named username.gitlab.io (put your Gitlab username in for “username”)
- Either Import from Github (or other) OR create/copy in your existing static website (if you had a Github Pages website, copy it here). If the latter, clone to your PC.
- on the Gitlab project page e.g.
Set up CI
- you’re automatically creating a
.gitlab-ci.ymlfile. Under the “apply a Gitlab CI Yaml template” pick appropriate for your site. If you’re coming from Github Pages it’s probably Jekyll.
- Your site is now building, as seen with the Pipelines tab of your website project. It takes about 3-4 minutes to install the gems for a Jekyll site, then 2-3 more minutes to complete the build depending on the size of your website. The public URL should be
username.gitlab.io. If it’s not found, be sure you name your repo
- Once you can browse
username.gitlab.io, in your Project Settings > Pages add TWO new domains if you have paid for your own domain name (here using
- This step can take your website down–consider this at low traffic times. Once you’re satisfied it works, you can setup/transfer DNS to Gitlab. Suppose your domain is
example.com, then set your DNS records to
example.com CNAME username.gitlab.io www CNAME username.gitlab.io
that’s assuming your DNS provider supports CNAME flattening such as Cloudflare.
Gitlab Pages used with for example Cloudflare works well to provide HTTPS with your custom domain name as per this procedure. With that procedure you can enable SSL “Full (Strict)” security.
The free Gitlab accounts currently give 2000 minutes/month build “pipeline” time. For a moderate sized website, let’s assume 5 minutes build time. So you could do 400 pushes/month or 13 pushes/day on average–that should be enough for a small to moderate website.
You can cancel pipelines / runs to save wasted builds if you made a push and then are making another push right after.