The all-new GitHub CLI has shipped! This now brings the power of GitHub to your terminal, on Windows, macOS, and Linux. GitHub is giving us the following capabilities:
- Run your entire GitHub workflow from the terminal, from issues through releases
- Call the GitHub API to script nearly any action, and set a custom alias for any command
- Connect to GitHub Enterprise Server in addition to GitHub.com
Install GitHub CLI
Following these links to install on Windows, macOS, and Linux.
On Windows, the gh CLI can be installed via an MSI file.
choco install gh
brew install gh
GitHub has published detailed instructions for different distros. TDLR installs below.
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-key C99B11DEB97541F0 sudo apt-add-repository -u https://cli.github.com/packages sudo apt install gh
sudo dnf config-manager --add-repo https://cli.github.com/packages/rpm/gh-cli.repo sudo dnf install gh
After running the install, I then ran my first ever gh command from WSL running in Windows Terminal.
The GitHub CLI seems to follow the standard for most command tools where the binary is called with a set of commands and subcommands along with flags that can be passed:
gh <command> <subcommand> [flags]
The tool lists the following as CORE COMMANDS:
gist: Create gists issue: Manage issues pr: Manage pull requests release: Manage GitHub releases repo: Create, clone, fork, and view repositories
There are also ADDITIONAL COMMANDS:
alias: Create command shortcuts api: Make an authenticated GitHub API request auth: Login, logout, and refresh your authentication completion: Generate shell completion scripts config: Manage configuration for gh help: Help about any command
Connecting gh to GitHub
With the gh CLI now installed, I need to authenticate to my GitHub account. One of the additional commands listed above was auth. I ran the following command to understand how to get connected.
gh auth --help
I can see now that I need to use the auth command with the login subcommand.
gh auth login --help
From the help, I see that the gh CLI supports an interactive login, so I run the following command and I will then have to select GitHub.com as my connection and to Login with a web browser.
gh auth login
The gh CLI tells me to copy a code and press Enter.
The web brower will then open to a GitHub.com page where, the code must be used to activiate the session, and then the gh CLI must be authorized by you to access your GitHub page.
You will need to make one further selection in the terminal window and that is to use HTTPS or SSH for your commands. I selected HTTPS. And with that I’m connected and ready to use the CLI!
gh CLI first commands
gh repo view build5nines/az-kung-fu
Next, I listed the issues on the repo:
gh issue list --repo build5nines/az-kung-fu
I then opened a new issue:
gh issue create --repo build5nines/az-kung-fu --title "Find Image missing list versions of images" --body "We are missing a command in this sample that lists all of the images a user has access to in the Azure Marketplace."
The issue can now be seen on GitHub
Well, I hope you enjoy getting started with the gh CLI! I’m going to be using this a lot in the future as I can see some awesome features here! Here is the CLI command reference.