GitLab command line access

Tags how-to

This article discusses how to access a private (or internal) GitLab project from the command line.

Objective

When connecting to a GitLab repo with restricted access you need to supply an access token for authentication. This guide will walk you through creating and using that access token.

Environment

A computer with the git command line utilities installed trying to connect to gitlab.umich.edu

Procedure

There are two main methods of authenticating with GitLab:

SSH:

The easiest way to connect to GitLab via the command line on a computer you use regularly is to setup SSH access. Set this up by following GitLab's documentation here: https://docs.gitlab.com/ee/ssh/

 

Project Level Tokens / Deploy Tokens:

  1. Create a new Repo using the GitLab web interface.
  2. Create a "deploy token" inside of a project from the SettingsRepositoryDeploy Tokens section.
  3. Create a new token with appropriate permissions. You probably want read_repository at a minimum and likely want write_repository so that you can also commit back to the repo with the same token.
  4. Copy the token that you create. It is only available for you to copy when you create it. If you don't copy it now then you will need to delete it and create a new one from scratch.
  5. Checkout the repository from the command line with the following format: git clone https://token name you picked:the personal access token@gitlab.umich.edu/user or project/repo name.

    For example, git clone https://testToken:kSyyszmxn1B4bymeqGQz@gitlab.umich.edu/lsa-ts-rsp/testProject.git uses the token name "testToken," the token generated is "kSyyszmxn1B4bymeqGQz," the project is "lsa-ts-rsp," and the repository is "testProject.git."


The access token and repo combination are saved to the git settings for that local repository so that you can now use normal git pull and git push commands without a password.

Note that you can also create a token in your user Account SettingsAccess Tokens settings. Tokens created in the Account Settings section are like a password to your entire GitLab account. It is recommended to use a repository specific token.

 

Public Projects

If your project is set to be public then you can push/pull without any special setup on another machine, but beware anyone can also access your project.

Details

Article ID: 1517
Created
Tue 5/26/20 6:05 PM
Modified
Thu 5/13/21 1:49 PM