Introduction to GitLab for developers

Photo by Erik Mclean on Unsplash

Why we use GitLab

As mentioned before there exists other web-based remote repositories servers. But we use GitLab for our developments projects for the following reasons:

  • GitLab allows us to locate a repository inside our organization server and to connect to it via our intranet using the free plan.
  • GitLab is less expensive for private repositories (unlimited number of private repositories).
  • GitLab strongly supports the CI/CD lifecycle with more flexibility.

Getting started on GitLab

To create a new project on GitLab you just need to click on the create New project button in the top sub-menu:

git clone http://gitlaburl/gitlab/username/my-first-project-on-gitlab.git
$ git clone http://gitlaburl/gitlab/username/my-first-project-on-gitlab.gitCloning into ‘my-first-project-on-gitlab’…
Username for ‘http://gitlaburl': *****
Password for ‘http://gitlaburl': *****
warning: You appear to have cloned an empty repository.

Add SSH key

When you first use GitLab you may come upon this warning message “You won’t be able to pull or push project code via SSH until you add an SSH key to your profile”.

$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (C:\Users\yourName/.ssh/id_rsa):
Created directory ‘C:\Users\aicha.yourName/.ssh’.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in C:\Users\aicha.fatrah/.ssh/id_rsa.
Your public key has been saved in C:\Users\yourName/.ssh/id_rsa.pub.
$ git clone git@gitlab****/my-first-project-on-gitlab.git
Cloning into 'my-first-project-on-gitlab'...
The authenticity of host 'gitlab.*****' can't be established.
ECDSA key fingerprint is SHA256:**********.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'gitlab.*****' (ECDSA) to the list of known hosts.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: UNPROTECTED PRIVATE KEY FILE! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0644 for '/home/aicha/.ssh/id_rsa' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Load key "/home/aicha/.ssh/id_rsa": bad permissions
git@gitlab******: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
$ sudo chmod 400 id_rsa
$ git clone git@gitlab.****:****/my-first-project-on-gitlab.git

Repository configuration

In a previous article, we talked about Branching strategies, we can configure GitLab to strict the respect of the Branching rules.

  • prevent their creation, if not already created, from everybody except Maintainers
  • prevent pushes from everybody except Maintainers
  • prevent anyone from force pushing to the branch
  • prevent anyone from deleting the branch
  • Maintainer: accepts merge requests on several GitLab projects.
  • Reviewer: performs code reviews on MR (merge requests).
  • Developer: has access to GitLab internal infrastructure & issues (e.g. HR-related).
  • Contributor: Can make contributions to all GitLab public projects

Merge requests and code review

To show how we create MR (merge requests) and review the code, we cloned the remote directory that we created above into our local machine and then create a branch that we called feature/uifrom develop , we added an HTML index.html file and added some content to it, then we added a commit and pushed the changes.

$ git checkout -b feature/ui develop
$ git add index.html
$ git commit -m "feat : first ui"
$ git push origin feature/ui

References:

--

--

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
Aicha Fatrah

Aicha Fatrah

Software Engineer | Technical Writer | IT Enthusiast