GitHub and GitLab Command Line Interfaces (CLIs)
Code hosting platforms like GitHub and GitLab provide command-line interfaces that make it possible to interact with their services from the terminal. These CLIs can also manage authentication to their respective services, ensuring that Git functionality in each editor works smoothly.
gh
for GitHub
- Install the GitHub CLI:
Follow these directions to install the CLI for all Workbench users.
Download a binary from the releases page and unpack to a location on the PATH
1, such as ~/.local/bin
:
$ wget -P /tmp https://github.com/cli/cli/releases/download/v2.14.4/gh_2.14.4_linux_amd64.tar.gz
$ tar xzvf /tmp/gh_2.14.4_linux_amd64.tar.gz -C ~/.local/ --strip-components=1
Using the terminal in your preferred editor, authenticate to GitHub by running:
$ gh auth login
- Select
yes
if you are prompted to re-authenticate; this will ensure that your authentication token has all the necessary scopes.
- Select
HTTPS
as your preferred protocol.
- Select
yes
if you are prompted toAuthenticate Git with your GitHub credentials
- If you select “Login with a web browser”, you will need to manually open
https://github.com/login/device
in another tab.
Example
gh auth login
output~ ❯ gh auth login ? What account do you want to log into? GitHub.com ? You're already logged into github.com. Do you want to re-authenticate? Yes ? What is your preferred protocol for Git operations? HTTPS ? Authenticate Git with your GitHub credentials? Yes ? How would you like to authenticate GitHub CLI? Login with a web browser ! First copy your one-time code: 9D3B-A1FD Press Enter to open github.com in your browser... /usr/bin/xdg-open: 851: /usr/bin/xdg-open: www-browser: not found /usr/bin/xdg-open: 851: /usr/bin/xdg-open: links2: not found /usr/bin/xdg-open: 851: /usr/bin/xdg-open: elinks: not found /usr/bin/xdg-open: 851: /usr/bin/xdg-open: links: not found /usr/bin/xdg-open: 851: /usr/bin/xdg-open: lynx: not found /usr/bin/xdg-open: 851: /usr/bin/xdg-open: w3m: not found xdg-open: no method available for opening 'https://github.com/login/device' ! Failed opening a web browser at https://github.com/login/device exit status 3 Please try entering the URL in your browser manually ✓ Authentication complete. - gh config set -h github.com git_protocol https ✓ Configured git protocol ✓ Logged in as workbench_user
- Select
Configure git to use GitHub CLI as a credential helper:
$ gh auth setup-git
Check your git config:
$ git config --global --list credential.https://github.com.helper=!/usr/bin/gh auth git-credential credential.https://gist.github.com.helper=!/usr/bin/gh auth git-credential
The gh
CLI should be configured as an HTTPS credential helper.
glab
for GitLab
Install the GitLab CLI
Create a Personal Access Token.
glab
requires at least theapi
andwrite_repository
scopes.Using the terminal in your preferred editor, authenticate to GitLab by running:
$ glab auth login
Example glab auth login
output
? What GitLab instance do you want to log into? gitlab.com
- Logging into gitlab.com
? You're already logged into gitlab.com as workbench_user. Do you want to re-authenticate? Yes
Tip: you can generate a Personal Access Token here https://gitlab.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 gitlab.com git_protocol https
✓ Configured git protocol
- glab config set -h gitlab.com api_protocol https
✓ Configured API protocol
✓ Logged in as workbench_user
- Check your git config:
$ git config --global --list
credential.https://gitlab.com.helper=!/usr/bin/glab auth git-credential
The glab
CLI should be configured as an HTTPS credential helper.