GitLab - LucianCumpata/DevOps GitHub Wiki

Welcome on my GitLab journey

Initial setup steps

  • Have an account and project on gitlab.com

We will skip this step as it's self explanatory and very easy to do.

There are two ways to clone your project using git: SSH or HTTPS.

SSH method:

  • Setup your SSH keys (mandatory for private projects/repos)

I use Windows 10 as my OS, so we will use WSL (Windows Subsystem for Linux) to create an SSH keys pair for gitlab.

  1. Check your SSH version

ssh -V

If you get:

-bash: ssh: command not found

You must install SSH on your machine:

sudo apt-get update

sudo apt-get install openssh-server

  1. Generate keys

We will generate and configure ED25519 key because it's considered more secure and performant than RSA keys.

ssh-keygen -t ed25519 -C "<comment>"

This will generate two keys: one public and one private. The public key you must add to gitlab:

User-settings -> SSH keys

Add the public key here!

  1. Configure keys

Copy the private key to /.ssh folder and change permissions:

chmod 400 example_key

Also run the following commands:

eval $(ssh-agent -s)

nano config and copy paste the following configurations:

# GitLab.com

Host gitlab.com

Preferredauthentications publickey

IdentityFile ~/.ssh/example_key

Also change the permissions for config file:

chomd 600 ~/.ssh/config

  1. Test and clone the repo

Run ssh -T [email protected] and type yes to add GitLab.com to the list of trusted hosts

Then run the above command again, and it should return you an

A successful run should return Welcome to GitLab, @username!

Now you should be able to git clone your repo

HTTPS method:

  1. Go to gitlab.com/profile/personal_access_tokens

  2. Type a name for the personal access token (PAT for short)

  3. Set an expiration date

  4. Check the api tick box under the Scopes

  5. Click create personal access token

  6. Now, at the top of the page you will see a new field with the personal access token. Save it somewhere safe because you won't be able to retrieve it after that.

  7. Clone the project:

git clone https://<user_name>:<token>@<domain>/<user_name>/<git_repo>

Example: git clone https://Lucian.Cumpata:[email protected]/Lucian.Cumpata/demo_repo.git/

The HTTPS link can be found on the repo page under the clone button -> Clone with HTTPS. Copy-paste that link and modify it with your username and personal access token.

Reference: https://gitlab.com/help/ssh/README#generating-a-new-ssh-key-pair

⚠️ **GitHub.com Fallback** ⚠️