DEV Community

Cover image for How to install and setup GitHub CLI
Yadunandan Bhat
Yadunandan Bhat

Posted on

How to install and setup GitHub CLI

You know how painful it is to switch from terminal to browser, then again to the terminal while working with git repositories right? Then worry not, because GitHub CLI brings GitHub to your terminal.

GitHub has finally introduced its own command-line tool that brings pull requests, issues, and other GitHub concepts to the terminal next to where you are already working with git and your code. To quote GitHub it "reduces context switching, helps you focus, and enables you to more easily script and create your own workflows". Pretty cool right?

This post explains the installation and the setting-up of the GitHub CLI, hereby referred to as 'gh'.

Installation

Windows

gh can be installed on Windows using scoop or chocolatey package managers.

scoop

scoop bucket add github-gh https://github.com/cli/scoop-gh.git
scoop install gh
Enter fullscreen mode Exit fullscreen mode

chocolatey

choco install gh
Enter fullscreen mode Exit fullscreen mode

macOS

macOS users can use either Homebrew or MacPorts to install gh.

Homebrew

brew install gh
Enter fullscreen mode Exit fullscreen mode

MacPorts

sudo port install gh
Enter fullscreen mode Exit fullscreen mode

Linux

Debain-based

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-key C99B11DEB97541F0
sudo apt-add-repository https://cli.github.com/packages
sudo apt update
sudo apt install gh
Enter fullscreen mode Exit fullscreen mode

Fedora-based

sudo dnf config-manager --add-repo https://cli.github.com/packages/rpm/gh-cli.repo
sudo dnf install gh
Enter fullscreen mode Exit fullscreen mode

Arch-based

sudo pacman -S github-cli
Enter fullscreen mode Exit fullscreen mode

There are more distro-specific installation instructions here. Windows and macOS users can install using MSIs and downloadable binaries available on their releases page.

Setting up

After the installation, running any command will prompt you to login to GitHub.

October 20 - 21-11-13.png

Run 'gh auth login' to authenticate your GitHub account. It'll ask you to select the account type, either a normal account or an enterprise one. I'll select the normal account.

October 20 - 21-13-28.png

Then it'll ask you to select your preferred authentication method. You can choose to authenticate using your browser or using the GitHub authentication token. I'll select the browser method.

October 20 - 21-13-51.png

Then it'll display a one-time code, you should copy it or write it down.

October 20 - 22-10-21.png

And then pressing enter will open the browser. You should enter the one-time code here.

October 20 - 21-16-16.png

Then click on "Authorize github" to complete the authentication. You can safely close the browser now.

October 20 - 21-17-08.png

Now it'll ask you to select the default git protocol. You can select HTTPS or SSH. I'll be selecting SSH because I've already made an SSH key, and it's easy cloning and pushing to the repo using SSH.

October 20 - 21-18-44.png

October 20 - 21-19-16.png

Aaaand that's it. You've successfully installed and set up the GitHub CLI.
I'm also planning a post explaining all the gh commands and how to use it, so be on the lookout for that.

Latest comments (2)

Collapse
 
nthdat profile image
nthdat • Edited

Nice wallpaper!
That terminal opacity is dope!

Collapse
 
yadunandanbhat profile image
Yadunandan Bhat

Thanks! I'm using compton for the transparency!