Git - GitLab Pages

New project setup

Now we see how to use GitLab and Git for code or blog versioning and deployment through the GitLab Pages feature.

Git setup

Install Git for Windows

First download the installer here.
Then you can start the installation. During the process, don’t forget to select the Credential Manager Windows option.
When Git is installed, Git BASH and Git GUI are enabled.

Create a local repository on existing code

In the our project’s directory with Git BASH or the windows console

C:\hugo\sites\blog\>git init
Initialized empty Git repository in C:/hugo/sites/blog/.git/

Create a SSH key

With Git Bash

$ ssh-keygen -t rsa -C "your.email@yourwebmail.com" -b 4096

The id_rsa.pub file is now created in %userprofile%\.ssh

GitLab setup

Create an account

Here

Create a new project

Connected with your previous GitLab account, go here

Declare the previous SHH key

On this page, paste the id_rsa.pub file content in the Key field, name it (Title field) and add it (Add key button)

Version control

In the windows explorer, go to the blog directory and start Git BASH

Verify the git configuration

$ git config --list

Configure git

User

For a local configuration (–global if not)

$ git config --local user.name "your name"
$ git config --local user.email "your.email@yourwebmail.com"
Remote repository
$ git remote add origin https://gitlab.com/your-gitlab-user/your-gitlab-project.git

To verify

$ git remote -v

If you have made a mistake, you can modify it with the following command

$ git remote set-url origin https://gitlab.com/your-gitlab-user/your-new-gitlab-project.git

Commit and push

First, if you want to exclude some files you have to create a .gitignore file in the project’s root.
For instance, for a HUGO blog which will run with the GitLab Pages feature, you have to ignore the public directory because its content will be automatically generated the CI/CD feature as we will see next.

Local commit
$ git add .
$ git commit -m "init commit"
Remote push
$ git push -u origin master

We can now modify our blog locally and push it in our remote repository.

GitLab Pages

You have to simply follow the instructions at this url To summarize, as our project is already created, we just have to activate the Continuous Integration / Continuous Delivary mode. To do this, create the .gitlab-ci.yml file in the blog’s root, commit and push.

# All available Hugo versions are listed here: https://gitlab.com/pages/hugo/container_registry
image: registry.gitlab.com/pages/hugo:latest

test:
  script:
  - hugo
  except:
  - master

pages:
  script:
  - hugo
  artifacts:
    paths:
    - public
  only:
  - master

In the GitLab project page, go to the Settings project’s menu, then in CI/CD go to Runners settings and click on Enable shared runners Henceforth, anytime you push your code, GitLab will generate the static website HUGO and deploy it.
Now, our blog is available at this URL : https://your-gitlab-user.gitlab.io/your-gitlab-project

git  gitlab  pages  setup 
comments powered by Disqus