Back to the main page

GitLab CLI tool

Intro

The glab is GitLab CLI tool.

Installation

The source and packages, like RPM for Linux are available at: https://gitlab.com/gitlab-org/cli/-/releases

Access token

You will need your own access token, it will be used by glab to access GitLab (this example is GitLab v14.0.1 on-prem) API. To create one, login to GitLab server web interface, go to User settings - Access Token, and "add personal access token" for application name "glab" with scope "api". Save it to secure location, because it won't be seen again. Finally, test glab authentication for your account:
$ glab auth login -h my-gitlab.domain.com

- Logging into my-gitlab.domain.com
  
Tip: you can generate a Personal Access Token here https://my-gitlab.domain.com/-/profile/personal_access_tokens
The minimum required scopes are 'api' and 'write_repository'.
? Paste your authentication token: ********************
? Choose default git protocol HTTPS
? Authenticate Git with your GitLab credentials? Yes
- glab config set -h my-gitlab.domain.com git_protocol https
¿ Configured git protocol
- glab config set -h my-gitlab.domain.com api_protocol https
¿ Configured API protocol
¿ Logged in as zdudic

Glab configuration

$ glab config set gitlab_uri my-gitlab.domain.com
  
$ glab config get gitlab_uri
my-gitlab.domain.com

Examples

The glab has many options, this page reads examples for some of them. To search for git repo containing string "mytools":
$ glab repo search -s mytools
  
Showing results for "mytools"
  devops-group/mytools  0 stars 0 forks 0 issues  updated about 1 day ago

GitLab repo info

To see git repo info, its readme me file:
$ glab repo view devops-group/mytools
  
devops-group / mytools
  
Readme: Scripts for DevOps tools by LabOps!

GitLab repo contributors

To list git repo contributors, you have to cd to git repo working directory and run this command there.
$ glab repo contributors
Showing 8 contributors on devops-group/mytools (Page 1)
 
Robert Plant 247 commits
Jimmy Page    50 commits
U2            27 commits
AC-DC         18 commits
Deep Purple    5 commits
The Clash      2 commits
Sex Pistols    1 commits

GitLab repo issue

Here, you'll need first to clone your repo, cd (change directory) to it, and run these commands there.

To list gitlab repo's issues:
$ glab issue list
Showing 1 open issue in devops-group/mytools that match your search (Page 1)
  
#1  devops-group/mytools Remove local cronjob (about 7 days ago)


Add a note to the issue
$ glab issue note 1 --message "This is completed"
  
https://my-gitlab.domain.com/devops-group/mytools/-/issues/1#note_862674


Close the issue
$ glab issue close 1
  
- Closing Issue...
¿ Closed Issue #1
#1 Remove local cronjob (about 7 days ago)
https://my-gitlab.domain.com/devops-group/mytools/-/issues/1


Back to the main page