I’have been asked how to use Git with Gitlab. Here is a tutorial that explains the process to follow.

1 Install Git client

1.1 Install Git on Windows

  1. Go to https://git-scm.com/.
  2. Download Git for Windows
    The website will automatically detect your operating system and provide the appropriate installer for your version of Windows.
  3. Run the Git installer usually named Git-x.x.x.x-64-bit.exe
  4. The installer will present you with a list of components to install. Ensure that “Git Bash” and “Git GUI” options are selected. These components provide a command-line interface and graphical user interface for interacting with Git.

  5. Choose the default editor. I like Notepad++.
    You can link Notepad editor after with the following command:

git config --global core.editor "'C:/Program Files (x64)/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"

To know the application location:

(get-command notepad++.exe).Path
  1. Adjust the PATH environment variable.
    Select the option “Use Git from the Windows Command Prompt” to ensure that Git commands can be accessed from the command prompt or PowerShell.

  2. Choose the line ending conversions. Git can handle different line endings in files. It’s recommended to select the default option “Checkout as-is, commit Unix-style line endings” unless you have specific requirements.

  3. Click the “Install” button to begin the installation process. The installer will copy the necessary files and set up Git on your system.
    Verify the installation
    Once the installation is complete, you can verify that Git is installed correctly. Open the command prompt or Git Bash, and type the following command:

git --version

If Git is installed properly, you’ll see the version number displayed in the output.

Congratulations! You have successfully installed Git on your Windows system. You can now start using Git for version control and collaboration on your projects.

1.2 Install Git on Mac

  1. Open your web browser and visit the official Git website: https://git-scm.com/.

  2. On the Git website, locate the download section and click on the macOS link. This will start the download of the Git installer.

  3. Once the download is complete, locate the downloaded file (usually in your “Downloads” folder) and double-click on it to start the installation process.

  4. A new window will appear, presenting the Git installer package. Double-click on the package to run it.

  5. The installer will guide you through the installation process. Click “Continue” to proceed.

  6. Read the license agreement and click “Continue” again. Then, click on the “Agree” button to accept the terms of the license.

  7. Choose the destination where you want to install Git. The default location should be fine for most users, so you can simply click “Continue” to proceed.

  8. On the “Installation Type” screen, you can customize the components to install. It’s recommended to leave the default options selected, which include the Git command line tools and the Git GUI. Click “Continue” to proceed.

  9. The installer will prompt you to enter your password. This is required to authorize the installation. Enter your macOS user account password and click “Install Software.”

  10. Wait for the installation process to complete. Once finished, you’ll see a “The installation was successful” message. Click “Close” to exit the installer.

  11. Open the Terminal application on your Mac. You can find it in the “Utilities” folder within the “Applications” folder. Alternatively, you can use Spotlight search (Cmd + Space) and type “Terminal” to launch it.

  12. In the Terminal window, type the following command and press Enter: git –version

If Git is installed correctly, you will see the version number displayed in the Terminal. Congratulations! Git is now installed on your macOS system.

That’s it! You have successfully installed Git on your macOS system. You can now use Git for version control and collaborate on projects.

1.3 Install Git on Linux

  1. Update your package lists: Open a terminal and enter the following command to update your package lists:
sudo apt update
  1. Install Git: Use the package manager to install Git by running the following command:
sudo apt install git
  1. Verify the installation: After the installation is complete, you can verify whether Git has been installed successfully by checking its version. Enter the following command:
git --version

This should display the version number of Git if the installation was successful.

  1. Configure Git: Before you start using Git, it’s a good idea to configure your user information. This information will be associated with any commits you make. Use the following commands to set your username and email address:
git config --global user.name "Your Name"
git config --global user.email "youremail@example.com"
Replace "Your Name" with your actual name and "youremail@example.com" with your email address.
  1. (Optional) Set up a text editor: By default, Git will use the system’s default text editor for commit messages and other editing tasks. However, if you prefer to use a different text editor, you can configure Git to use it. For example, to set the text editor to Nano, run the following command:
git config --global core.editor "nano"

Replace “nano” with the name of your preferred text editor.

Congratulations! You have successfully installed Git on Linux and configured it with your user information. You can now start using Git to manage your version control needs.

2. Create a SSH key

First you need to create a SSH key.
In order to create the SSH key, you can use a tool called SSH-keygen. It is simply a tool that allows creating authentication key pairs for SSH. Therefore you can connect to applications automatically. SSH key pairs are also used for single sign-on, and for authenticating hosts.
Here are the steps to follow:
1. run ssh-keygen without arguments. This will generate public/private rsa key pair.
The tool asked where to save the file. Press enter. The key files are usually stored in the user’s .ssh directory under the home directory.
2. It will ask for a passphrase. If you do not need a password when you use the key, leave it empty.
3. Go the saving location and open the id-rsa.pub file with your favorite note application like notepad++
4. Copy the content of the file, we will use it in 5 minutes.

:fire:The default key file names depend on the used algorithm. Most of the time, like in this case, the file name is id_rsa when using the default RSA algorithm. It could also be, for example, id_dsa or id_ecdsa.

a detailed command line could be also provided like this:

ssh-keygen -t rsa -b 4096 -C "my-email@my-domain.com"

Here we provided an old algorithm based on the difficulty of factoring large numbers (rsa). You can different algorithms: dsa, ecdsa, ed25519,…

2.1 Add you SSH key on Gitlab

  1. Open your favorite browser and go to Gitlab.
  2. Connect to your account or use a free trial
  3. Go to your account settings, then ssh-eys, as illustrated below:
  4. Paste the content of the id-rsa.pub we have copied before in the key text field.

2.2 Configure Git

  1. Set global username/email in command line:
    git config --global user.name "FIRST_NAME LAST_NAME"

    git config --global user.email "MY_NAME@hinfact.com"

  2. Configure CRLF files
    git config --global core.autocrlf true

Now you are ready to read an apply our article on Conventional Commit with Git, or use Gitlab with Git.

3. Setup a new project on Gitlab

  1. Think about the name of your project and select a group if there is any.
  2. Create a Merge Request template, so that developers and reviewers could follows dedicated instructions during a merge request. (See the section below for more details).
  3. Configure the correct options on the repository on gitlab to follow our ‣
  4. Adds relevant CI/CD templates, an example of c++ ci/cd template can be found here
  5. For more automated process, you can use N8N integration to send a push notification on a communication channel (e.g, Mail, Slack, …) whenever the CI/CD pipeline succeeds or fails.

4. Merge-request templates

4.1 Create a Merge-request template

Merge request template is a “.md” file that contains all the instructions.

In your Git repository, add the template in .gitlab/merge_request_templates folder.


## Describe your Task:
*Link the Notion task or explain what this MR does and why*

## Developer checklist
*This checklist must be done before review*
- [ ] The branch is up-to-date with `main` (git rebase)
- [ ] The code is clean and easily readable
- [ ] All unit tests are done
- [ ] The documentation if updated (comments, README)

## Reviewer checklist
*This checklist must be completed by the reviewer before approving*
- [ ]  I can understand this MR
- [ ]  I can read the code easily
- [ ]  I have tested the code block,
- [ ]  I have validated the results
- [ ]  I have checked the tested

4.2 Use the Merge-request template

You can use Merge-request templates to add instructions to follows for reviewers, maintainers and developers during each merge-request.
Follow these steps:

  • Create a merge request.
  • Select the Choose a template dropdown list.
  • If the Description text box hasn’t been empty, to confirm, select Apply template.
  • Select Save changes.

5. Git Local Runner for CI/CD

CI/Cd stands for Continuous Integration and Continuous Delivery.

Git uses runner to execute CI/CD pipelines. This is mostly done on Gitlab servers but one can use her own local computer as a local runner.

GitLab Runner can be used with Docker or be deployed to a Kubernetes cluster.

Here is how to install Gitlab runner on macOs, Windows and Linux.

You must also register your runners with your GitLab instance.

Download this example of Gitlab CI/CD pipeline file. Rename it .gitlab-ci.yml.
This file is used in the Gitlab game demo.

Written by

Albert Oplog

Hi, I'm Albert Oplog. I would humbly like to share my tech journey with people all around the world.