gitlab icon feature

Background

As many of my readers probably know, much of my work these days revolves around building, managing and supporting technical teams. However, when time permits, I love doing real technical hands-on work.

In recent times, I’ve invested a reasonable amount of time learning the GitLab platform, which I not only find interesting, but it helps me to support teams at the day job who are engaged in migrating from a range of bespoke tools into a single location.

For those who don’t know, Gitlab is a web-based Git repository manager that provides source code management, continuous integration, wikis, container/artefact registries and more, all in one platform. 

The source of its power comes (mostly) from what’s known as the .gitlab-ci.yml, which is used to define the build, test, and deployment steps for a project. This file is placed in the repository’s root directory (or somewhere defined by the engineer). It is then used by the GitLab continuous integration (CI) system to automate the build, test, and deployment processes. Anyways, that’s a topic for another post.

Recently I started a new GitLab project and need to connect via HTTPS using a personal access token. I realised it’d been a while since I’d started a project from scratch, and the detailed instructions of what’s required had left my memory. This time I thought I’d document the task, not only to help remember for next time but to help anyone else that might have run into the same issue.

New Configuration

Here are the steps to clone a repo via HTTPS and authenticate you with the personal access token: 

1. First, generate a personal access token @ GitLab. You can do this by signing in to your Settings -> Access Tokens and clicking the “Create personal access token” button. At this stage, give the token a name and set the expiration date to sometime in the future.

2. Next, you will need to copy the token generated for you. It will be displayed on the page, and you need to copy it to your clipboard or to your password/token database.

3. Open a terminal or command prompt and navigate to the directory where you want to clone the repository.

4. Use the git clone command to clone the repository, but use the

https://oauth2:<PAT>@gitlab.com/<USERNAME>/<REPO>.git

URL format, replacing <PAT> with your personal access token and <USERNAME> and <REPO> with the appropriate values for your GitLab user and repository.

As an example, say your personal access token is acbdehgjiwklmnopqrrrrrwxyz with a GitLab username of scottoau, and the name of your repository is awesome-app, you would run the following command:
git clone https://oauth2:[email protected]/scottoau/awesome-app.git

Configuration File

If you have an existing project, one which you’ve already initiated and checked out with git, you can add a new origin to the .git/config file within your project directory.

...
[remote "origin"]
        url = https://oauth2:[email protected]/scottoau/awesome-app.git
        fetch = +refs/heads/*:refs/remotes/origin/*
...

I hope this helps! As always, reach you if you have any questions or comments.