Learn about GitHub's new CLI called "gh" (In beta)

Introduction

 
GitHub team recently introduced a new CLI tool called "gh", which is available in beta right now. In your day to day coding as well as development activities, you use a lot of commands of existing tool called "git" for certain operations  and go to the github.com for the other operations. To overcome this back and forth situation, GitHub team has launched a new CLI tool "gh" which brings a lot of awesome features like creating issues, view issues, pull requests, creating a repo, cloning a repo, opening the browser with your repo, etc. that you can use through your command-prompt (terminal) in one place.
 
GitHub's official command-line tool - https://github.com/cli/cli
 

Download and Installation

 
You can download this tool on Windows, Mac and other platforms using different sources. On Windows, you can download MSI and install it using the given link (download for Windows) on its official website, shown below.
 
 
Know About GitHub New CLI Called
 
To download and install the tool on another platform rather than Windows, use the following official link.
 
After installation, you can check "gh" version using the following command,
 
> gh --version
 
Know About GitHub New CLI Called
 

Some Useful CLI Commands

 
Creating a GitHub Repo
 
To create a new GitHub repository, use the following command with flags (for giving description & to make public).
 
> gh repo create <repo-name> -d "<a small description about repo>" --public
 
Flags
 
-d / --description : Description about repository
--public : Make the public repository
 
Know About GitHub New CLI Called
 
For more description/flags about creating a repository, use this link.
 
Open the browser to view your repo
 
To view your just created or any repository ("Articles" in my case) in the browser, you don't need to go to the browser and hit the URL now. You can just use the following command:
 
> gh repo view -w
 
Flags
 
-w / --web : To open and view your GitHub repository in the browser
 
Know About GitHub New CLI Called
 
You can see my recently created repo via the below snapshot:
 
Know About GitHub New CLI Called
 
Cloning a GitHub repository
 
You can also close an existing GitHub repository to your local computer using the following command:
 
> gh repo clone [email protected]:rahul230691/Articles.git
 
Forking a GitHub repository
 
You can also fork your own copy of any GitHub repository as well as clone it to your local computer using the following command,
 
> gh repo fork dotnet/aspnetcore --clone
 
Flags
 
dotnet/aspnetcore - official aspnetcore repository which I forked to my account
--clone - wants to close to your local computer along with a fork
 
Know About GitHub New CLI Called
 
Creating a new issue
 
You can also create a new issue with your command-window (terminal) from your local machine using the following command:
 
> gh issue create -t "<issue-title>" -b "<issue-body>"
 
Flags
 
-t / --title - Provides a title string, otherwise it will give you a prompt window
-b / --body - Provides a body (description) about the issue, otherwise, it will give you a prompt window
-w / --web - Open the browser to create an issue
 
Know About GitHub New CLI Called
 
There are a few more useful "issue" commands about viewing your issues, seeing about the status of your issues and getting the list of open issues.
 
For the entire issues list on GitHub repository, use the following command:
 
> gh issue list [flags]
 
Flags
 
-a / --assignee - To get issue list by assignee
-A / --author - To get issue list by author
-l / --label - To get issue list by label
-L / --limit - To get the maximum number of list (By default, it is 30)
-s / --state - To get issue list by state (e.g. open/closed/all) (By default, it is open)
 
Know About GitHub New CLI Called
 
To get issue status, use the following command:
 
> gh issue status
 
Know About GitHub New CLI Called
 
Help commands
 
You can get help for any sub-commands, any repo commands, any issue commands using the provided help option (--help). See the following example.
 
> gh --help
> gh repo --help
> gh issue --help
and more.
 
Read the full documentation for the new GitHub CLI here.
 

Summary

 
In this article, we learned about a new CLI tool called "gh", recently launched by the GitHub team. Thanks a lot for reading, I hope you will love this article. Please share your valuable suggestions and feedback, and feel free to write in the comment box in case you have any questions. Have a good day!