cli

module
v1.27.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 5, 2023 License: MIT

README

GLab

GLab

Go Report Card Coverage Mentioned in Awesome Go Gitpod Ready-to-Code

GLab is an open source GitLab CLI tool bringing GitLab to your terminal next to where you are already working with git and your code without switching between windows and browser tabs. Work with issues, merge requests, watch running pipelines directly from your CLI among other features.

glab is available for repositories hosted on GitLab.com and self-managed GitLab instances. glab supports multiple authenticated GitLab instances and automatically detects the authenticated hostname from the remotes available in the working Git directory.

command example

Table of contents

Usage

To get started with glab:

  1. Follow the installation instructions appropriate for your operating system.
  2. Authenticate into your instance of GitLab.
  3. Optional. Configure glab further to meet your needs:

You're ready!

Core commands

Run glab --help to view a list of core commands in your terminal.

Commands follow this pattern:

glab <command> <subcommand> [flags]

Many core commands also have sub-commands. Some examples:

  • List merge requests assigned to you: glab mr list --assignee=@me
  • List review requests for you: glab mr list --reviewer=@me
  • Approve a merge request: glab mr approve 235
  • Create an issue, and add milestone, title, and label: glab issue create -m release-2.0.0 -t "My title here" --label important

Demo

asciicast

Documentation

Read the documentation for usage instructions or check out glab help.

Installation

Download a binary suitable for your OS at the releases page. Other installation methods depend on your operating system.

Homebrew

Homebrew is the officially supported package manager for macOS, Linux, and Windows (through Windows Subsystem for Linux)

  • Homebrew
    • Install with: brew install glab
    • Update with: brew upgrade glab
Other installation methods

Other options to install the GitLab CLI that may not be officially support or are maintained by the community are also available

Building from source

If a supported binary for your OS is not found at the releases page, you can build from source:

Prerequisites for building from source
  • make
  • Go 1.18+

To build from source:

  1. Run the command go version to verify that Go version 1.18 or later is installed. If go is not installed, follow instructions on the Go website.
  2. Clone this repository: git clone https://gitlab.com/gitlab-org/cli.git glab
  3. Change into the project directory: cd glab
  4. If you have $GOPATH/bin or $GOBIN in your $PATH, run make install to install in $GOPATH/bin).
  5. If you do not have $GOPATH/bin or $GOBIN in your $PATH:
    1. Run make to build the project.
    2. Run export PATH=$PWD/bin:$PATH to update your PATH with the newly compiled project.
  6. Run glab version to confirm that it worked.

Authentication

To authenticate your installation of glab:

  1. Get a GitLab personal access token with at least the api and write_repository scopes. Use the method appropriate for your instance:
    • For GitLab.com, create one at the Personal access tokens page.
    • For self-managed instances, visit https://gitlab.example.com/-/profile/personal_access_tokens, modifying gitlab.example.com to match the domain name of your instance.
  2. Start interactive setup: glab auth login
  3. Authenticate with the method appropriate for your GitLab instance:
    • For GitLab SaaS, authenticate against gitlab.com by reading the token from a file: glab auth login --stdin < myaccesstoken.txt
    • For self-managed instances, authenticate by reading from a file: glab auth login --hostname gitlab.example.com --stdin < myaccesstoken.txt. This will allow you to perform authenticated glab commands against a self-managed instance when you are in a Git repository with a remote matching your self-managed instance's host. Alternatively set GITLAB_HOST to direct your command to your self-managed instance.
    • Authenticate with token and hostname: glab auth login --hostname gitlab.example.org --token xxxxx Not recommended for shared environments.

Configuration

By default, glab follows the XDG Base Directory Spec. Configure it globally, locally, or per host:

  • Globally: run glab config set --global editor vim.
    • The global configuration file is available at ~/.config/glab-cli/config.yml.
    • To override this location, set the GLAB_CONFIG_DIR environment variable.
  • The current repository: run glab config set editor vim in any folder in a Git repository.
    • The local configuration file is available at .git/glab-cli/config.yml in the current working Git directory.
  • Per host: run glab config set editor vim --host gitlab.example.org, changing the --host parameter to meet your needs.
    • Per-host configuration info is always stored in the global configuration file, with or without the global flag.
Configure glab to use your self-managed instance

When outside a Git repository, glab uses gitlab.com by default. For glab to default to your self-managed instance when you are not in a Git repository, change the host configuration settings. Use this command, changing gitlab.example.com to the domain name of your instance:

glab config set -g host gitlab.example.com

Setting this configuration enables you to perform commands outside a Git repository while using your self-managed instance. For example:

  • glab repo clone group/project
  • glab issue list -R group/project

If you don't set a default domain name, you can declare one for the current command with the GITLAB_HOST environment variable, like this:

  • GITLAB_HOST=gitlab.example.com glab repo clone group/project
  • GITLAB_HOST=gitlab.example.com glab issue list -R group/project
Configure glab to use self-signed certificates for self-managed instances

The GitLab CLI can be configured to support self-managed instances using self-signed certificate authorities by making either of the following changes:

You can disable TLS verification with:

glab config set skip_tls_verify true --host gitlab.example.com

Or add the path to the self signed CA:

glab config set ca_cert /path/to/server.pem --host gitlab.example.com

Environment variables

  • GITLAB_TOKEN: an authentication token for API requests. Setting this avoids being prompted to authenticate and overrides any previously stored credentials. Can be set in the config with glab config set token xxxxxx
  • GITLAB_URI or GITLAB_HOST: specify the URL of the GitLab server if self-managed (eg: https://gitlab.example.com). Default is https://gitlab.com.
  • GITLAB_API_HOST: specify the host where the API endpoint is found. Useful when there are separate (sub)domains or hosts for Git and the API endpoint: defaults to the hostname found in the Git URL
  • GITLAB_REPO: Default GitLab repository used for commands accepting the --repo option. Only used if no --repo option is given.
  • GITLAB_GROUP: Default GitLab group used for listing merge requests, issues and variables. Only used if no --group option is given.
  • REMOTE_ALIAS or GIT_REMOTE_URL_VAR: git remote variable or alias that contains the GitLab URL.
  • GLAB_CONFIG_DIR: Directory where glab's global configuration file is located. Defaults to ~/.config/glab-cli/ if not set. Can be set in the config with glab config set remote_alias origin
  • VISUAL, EDITOR (in order of precedence): the editor tool to use for authoring text. Can be set in the config with glab config set editor vim
  • BROWSER: the web browser to use for opening links. Can be set in the configuration with glab config set browser mybrowser
  • GLAMOUR_STYLE: environment variable to set your desired Markdown renderer style Available options are (dark|light|notty) or set a custom style
  • NO_COLOR: set to any value to avoid printing ANSI escape sequences for color output.
  • FORCE_HYPERLINKS: set to 1 to force hyperlinks to be output, even when not outputting to a TTY

Issues

If you have an issue: report it on the issue tracker

Contributing

Feel like contributing? That's awesome! We have a contributing guide and Code of conduct to help guide you.

Directories

Path Synopsis
api
This is a silly wrapper for go-gitlab but helps maintain consistency
This is a silly wrapper for go-gitlab but helps maintain consistency
cmd
api
ci
ci/legacyci
This package contains the old `glab pipeline ci` command which has been deprecated in favour of the `glab ci` command.
This package contains the old `glab pipeline ci` command which has been deprecated in favour of the `glab ci` command.
mr
mr/diff
adapted from https://github.com/cli/cli/blob/trunk/pkg/cmd/pr/diff/diff.go
adapted from https://github.com/cli/cli/blob/trunk/pkg/cmd/pr/diff/diff.go
internal
run
pkg
git
surveyext
this is a wrapper for https://github.com/AlecAivazis/survey package but with additional extensions and customizations for glab adapted from https://github.com/cli/cli/blob/trunk/pkg/surveyext/editor.go
this is a wrapper for https://github.com/AlecAivazis/survey package but with additional extensions and customizations for glab adapted from https://github.com/cli/cli/blob/trunk/pkg/surveyext/editor.go

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL