How To Use GitHub from your terminal with GitHub CLI

Steve Pesce
3 min readSep 19, 2020

Personally, I never liked switching back and forth between my browser and terminal when working with git repos on GitHub. For this reason, I was excited to hear about the new GitHub CLI.

Installing GitHub CLI 1.0 (beta)

MacOS

  • homebrew:
brew install gh
  • macPorts:
sudo port install gh

Windows

  • scoop:
scoop bucket add github-gh https://github.com/cli/scoop-gh.git
scoop install gh
  • chocolatey:
choco install gh
  • manual:
download the msi from https://github.com/cli/cli/releases/tag/v1.0.0

Linux

If you have Homebrew installed, you can simply use:

brew install gh
  • apt:
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
  • dnf:
sudo dnf config-manager --add-repo https://cli.github.com/packages/rpm/gh-cli.repo
sudo dnf install gh
  • zypper:
sudo zypper addrepo https://cli.github.com/packages/rpm/gh-cli.repo
sudo zypper ref
sudo zypper install gh
  • manual:
download the tar from https://github.com/cli/cli/releases/tag/v1.0.0

I will be using Homebrew on WSL Ubuntu for my setup. Follow the appropriate installation instructions from the step above, and you should have the same results.

Follow installation instructions

Authentication

You must connect to your GitHub account to start using the CLI.

Run gh auth login to start connecting your account.

Next select GitGub.com and then selectPaste an authentication token

Note: I already authenticated, I am reauthenticating to show the process.

Follow the link to get your token: https://github.com/settings/tokens , generate a new token, and paste it into the terminal.

Now select your protocol, I use SSH.

Optional: Run gh auth status to make sure you are logged in.

Creating a New Repo

To create a repo run gh repo your-repo-name

Optionally, you can use flags, for example the -d flag sets the repo’s description.

Include a description when creating a repo

You will need to tell git where to push for your first push.

Cloning a Repo

gh repo clone <repo>

You can clone a repo using the owner/repo syntax. For example, to clone the repo that I just created, you would use gh repo clone sPesce/my-descriptive-repo . For this example, I will clone the GitHub CLI repo.

That should be enough to get you familiar. GitHub CLI has great documentation — the manual should guide you in performing any of its other functions.

--

--