DEV Community

Cover image for Github CLI -  official tool
Anubhav sharma
Anubhav sharma

Posted on

Github CLI - official tool

Github is the most amazing, powerful platform for developers, engineers, and even for organizations as well for serving as a home to millions of projects including open source and some personal projects as well.
Being a terminal lover, working on the terminal is fascinating. Hub has been serving as an unofficial powerful CLI tool for GitHub and it has been mentioned on their website also.


But a few months ago, the company has decided to serve its purpose and came out with the official command-line tool GitHub CLI so that you don't have to leave your terminal.

The tool was in the beta stage until September. Then it has been released with its first version v1.0.

Installation

The installation is very simple.


On macOS, it is available via brew

brew install github/gh/gh
Enter fullscreen mode Exit fullscreen mode



On Windows, it is available via three methods :

  • Scoop
  scoop bucket add github-gh https://github.com/cli/scoop-gh.git
  scoop install gh 
Enter fullscreen mode Exit fullscreen mode
  • WinGet
winget install gh
Enter fullscreen mode Exit fullscreen mode
  • Chocolatey
choco install gh
Enter fullscreen mode Exit fullscreen mode



On Linux, it is available via brew. For more instructions, see the Linux installation docs

Commands

While hub already supports more commands, hub behaves as a proxy to Git and gh is a standalone tool.

All commands in the CLI start with gh.
I have stated several commands for pull requests and issues. For more commands, you can check upon this Manual

Managing PULL REQUESTS

For pull requests, we use pr along with gh. There are several subcommands for managing pull requests -

  • list- this helps in listing the pull requests that have been made on the given repository.
gh pr list [flags]
Enter fullscreen mode Exit fullscreen mode
  • status- this tells us about the status of the active pr, we can provide the info of the requests for which we want to check the status.
gh pr status [flags]
Enter fullscreen mode Exit fullscreen mode
  • view- this command is used to view the pull request, title, the code along with the pr, body, etc.
gh pr view [<number> | <url> | <branch>] [flags]
Enter fullscreen mode Exit fullscreen mode
  • create- as the word suggests, this command is used to create a pull request. You can use different flags like title body etc. to pr, just go and check the manual for flags.
gh pr create [flags]
Enter fullscreen mode Exit fullscreen mode
  • checkout- this command is used to check out a pull request using the pull request number or URL if you have it.
gh pr checkout {<number> | <url> | <branch>} [flags]
Enter fullscreen mode Exit fullscreen mode
  • close- this command closes the pull request provided the pull request number, URL which you want to close.
gh pr close [<number> | <url> | <branch>] [flags]
Enter fullscreen mode Exit fullscreen mode

For more commands related to managing the Pull requests, you can check out this.

The [flags] part generally represents the parameters values you want to provide with the command. You can check the manual for that.

ISSUES

We use the issue command with gh to deal with issues on GitHub.There are several commands that are used with issue command -

  • create- you can use the below command to create an issue.
gh issue create [flags]
Enter fullscreen mode Exit fullscreen mode
  • list- it lists out all the issues that are currently present in the repository.
gh issue list [flags]
Enter fullscreen mode Exit fullscreen mode
  • status- check the status of the issue, whether it is closed or open
gh issue status [flags]
Enter fullscreen mode Exit fullscreen mode
  • view- it outputs the information about the issue provided by the number or URL of the issue.
gh issue view {<number> | <url>} [flags]
Enter fullscreen mode Exit fullscreen mode
  • close- it closes the issue.
gh issue close {<number> | <url>} [flags]
Enter fullscreen mode Exit fullscreen mode



NOTE- Just don't get confused with the flags part, I have provided the link for the manual above. Go and check out and add flags as per your need.

Top comments (0)