Learn GitHub CLI, a tool that enables you to use GitHub functionality alongside Git commands without having to leave the command-line interface.

In this quickstart guide, you’ll learn GitHub CLI. Find out what the GitHub CLI tool is used for, how to set it up, and how to use it.

If you’re already familiar with Git commands, you’re obviously aware that you need to switch to the web browser in order to perform various actions on your GitHub repository. With the new GitHub CLI tool, you can execute many of these actions without leaving the command-line interface.

Setup

To get started, simply visit the installation page and find instructions on how to install GitHub CLI for your operating system. For Windows and macOS, you can use package managers to install and keep GitHub CLI up to date. For Linux users, you’ll need to download the package from the latest release page. There are Signed MSI installers for Windows users too, but be aware you have to re-download and update the tool manually if you opt for this. The easiest way for Windows users is to use the scoop package manager.

Below are snapshots of install instructions for each supported platform:

  • Windows:
scoop bucket add github-gh https://github.com/cli/scoop-gh.git
scoop install gh
  • macOS:
brew install github
  • Debian/Ubuntu Linux:
sudo apt install git && sudo dpkg -i gh_*_linux_amd64.deb
  • Fedora/Centos Linux:
sudo yum localinstall gh_*_linux_amd64.rpm
  • Arch Linux:
yay -S github-cli

On Windows, I would recommend the use of the Git Bash terminal. This interface will allow you to access common Linux commands and Bash features such as autocompletion. It’s also officially supported by Visual Studio Code via terminal integration.

After installing GitHub CLI, you’ll need to authenticate your account. Running any command will trigger this authentication process. For example, try gh repo view cli/cli. For first-time users, you’ll be prompted with the following:

GitHub authentication

Simply press the Enter key to start the process as illustrated below:

Gitub authorization

Once you provide your password, you’ll get a “Successfully authenticated GitHub CLI” message. You’re now able to interact with the GitHub platform via the command-line terminal. The next step is to implement autocomplete, which is optional. Simply add this line to your ~/.bash_profile:

eval "$(gh completion -s bash)"

You can also run the above command in your current terminal to get the autocomplete feature without restarting your terminal. To confirm it’s working, type gh repo, then press tab twice. It should show you four different commands you can append to the current repo command.

Command Structure

The gh command structure is tree-like and easy to remember. There are basically two levels of commands. The first level only consists of six commands:

  • config
  • repo
  • issue
  • pr
  • gist
  • credits

Each command has a second level of command where you can specify the operation you want to perform — such as gh repo view or gh pr list. The credits command has no second-level command, though. When executed, it simply lists the names of a repository’s contributors. Here’s a quick example you can try out yourself:

$ gh credits cli/cli

We’ll look at the rest of the commands in more detail in the upcoming sections.

#github #git #developer

Learn GitHub CLI: Your Guide to GitHub from the Command Line
2.95 GEEK