DEV Community

Cover image for Try gh, GitHub's new CLI
John Papa for Microsoft Azure

Posted on • Originally published at johnpapa.net

Try gh, GitHub's new CLI

Quiz: What do you use every day, that is essential to your development workflow, and has a vast and complex UI and API?

Answer: GitHub, of course!

You likely interact with the git commands in terminal for some operations and then go to the https://github.com web site when you need to perform other operations. This back and forth between terminal and the browser to perform git operations could be more efficient if you could stay in one zone: CLI or the browser: Well, the GitHub team has felt this too.

They have released a new CLI called gh, in beta.

Resources first

If you are in a hurry, here are all of the links you'll need, in one place:

Install gh

First, install gh using the appropriate instructions for your OS.

You can check your version at anytime with the following command.

gh --version

Awesome Possibilities

{ 1 } Create an issue

You're working on your code and you run into a bug. But you are busy working on another challenge and don;t want to get distracted. Now you can run a quick command to create an issue without leaving your terminal!

This is awesome! Now you can stay focused on your current work and get back to this later.

gh issue create -t "Save invokes a 500 error" -b "steps to reproduce: fill out the form, then press save."

{ 2 } View issues

Want to see what issues are open?

gh issue status

This produce the following output format:

Relevant issues in johnpapa/hello-worlds

Issues assigned to you
  There are no issues assigned to you

Issues mentioning you
  There are no issues mentioning you

Issues opened by you
  #1  Save invokes a 500 error    about 1 minute ago

{ 3 } Create a repo

You know how sometimes you want to create a repo locally and in GitHub from your computer? Use the following command and you can create a repo named hello-world, add a description, and make the repo public!

gh repo create hello-world -d "A react app for the web" --public

{ 4 } Open the browser to your repo

You're working on your code locally and you want to go visit the repo in the browser. Now you have to go type in that URL in the address bar. Nope! Run the following command from your code's local folder and the browser opens right to your repo!

gh repo view
# this will open your repo, such as https://github.com/johnpapa/hello-world

{ 5 } Clone a repo

You can run some common commands like cloning a repo too.

gh repo clone git@github.com:johnpapa/hello-world.git

{ 6 } Fork a repo

Want to fork a repo? How about fork it and clone it locally to your computer? Try this command.

gh repo johnpapa/hello-worlds fork --clone

{ 7 } Create a pull request

You've made your changes to your branch and now it is time to create a Pull Request (PR). You could go to the browser, browse to your repo, and start clicking around to create the PR. Or you could use the following command to create a PR!

The --fill flag indicates that you won't be prompted for title/body. Instead it will just use the commit info for those.

gh pr create --fill

{ 8 } Help commands

A great place to start is with the --help flag. You can show the options available for any command by appending the --help flag.

get help on commands

gh --help

sub commands

gh issue --help
gh pr  --help
gh repo --help

pr commands

gh pr checkout --help
gh pr create --help
gh pr list --help
gh pr status --help
gh pr view --help

repo commands

gh repo clone --help
gh repo create --help
gh repo fork --help
gh repo view --help

issue commands

gh issue create --help
gh issue list --help
gh issue status --help
gh issue view --help

{ 9 } Read the docs

There is a lot more that you can do, so go ahead and read the gh docs.

{ 10 } git is still awesome

No worries, you can mix and match using the git commands and the gh commands.

Summary

Give it gh a try! GitHub is accepting feedback now during their beta through this short survey.

Top comments (7)

Collapse
 
sergix profile image
Peyton McGinnis

Awesome!! This will be great for CI/CD pipelines.

Collapse
 
richeney profile image
Richard Cheney • Edited

For WSL2 users, create a ~/.config/gh/config.yml file to authenticate to GitHub:

http://github.com:
  - user: ${github username}
    oauth_token: ${personal access token}

Using personal access tokens generated on GitHub. This will become a slicker process over time.

Collapse
 
jamesqquick profile image
James Q Quick

wow, this is cool. I had no idea there was a CLI lol

Collapse
 
rmfossi profile image
rmfossi

Hi John (et al), I'm new to the programming and github scene... Does gh not offer a way to create a new branch once you've cloned locally? I've been digging around for this info, and all I can find is information on creating a pr with the gh pr command.
As you suggest at the end of your article, should I just use the git command for creating my local branch, and gh for the rest?

Collapse
 
sandeepbalachandran profile image
Sandeep Balachandran

Wow. Great. Sounds interesting. Just for the clarification. What about the old CLI?

Collapse
 
john_papa profile image
John Papa

yep .. git still works (see #10)

Collapse
 
kazmierczakpiotr profile image
Piotr Kaźmierczak

What did u refer to? 'hub' cli, or simply to 'git'?