A-Z Guide to Github CLI (gh)
Are you a terminal lover? Ever thought of working with Github issues and pull requests on the command line? This is an introduction to the right tool to help with your problems.
Github already has an increasing user base since it supports an unlimited number of private repositories and now, it also has a new open-source tool gh.
As per the official documentation, gh
is GitHub on the command line, and it's now available in beta. It brings pull requests, issues, and other GitHub concepts to the terminal next to where you are already working with git
and your code.
Installation
Please follow this link to install gh on your system:
gh
is available for Windows, macOS and Linux.
After installing, just open the terminal to check gh is installed properly or not.
gh --version
The version at the time of writing this article was 0.5.5, you can also verify your output as:
gh version 0.5.5 (2020-02-13)
https://github.com/cli/cli/releases/tag/v0.5.5
So, gh is up and ready. Let’s dive in.
Basic Commands
- gh issue : Create and view issues
- gh pr : Create, view, and checkout pull requests
Time to get our hands dirty.
gh issue
While working withgh issue
command, the available commands as of now - create, list, status, view
- create : To create an issue you need to type,
gh issue create
and it will ask you for the title of the issue, the body of the issue and at last which action to perform like view the issue in the browser, submit/cancel it.
2. list : You can see the list of issues by typing gh issue list
3. status : To check the status of the issues, type gh issue status
4. view : To view the issue in the browser, you need to type the command with the id of the issue. gh issue view 1
gh pr
While working withgh pr
command, the available commands as of now - create, list, status, checkout, view
- create : To create a pull request from the current branch, you need to type
gh create pr
NOTE : If you want to create a PR for a specific branch, you need to pass -B flag with the command followed by the branch name.
I have created a PR from feature/new-pr
branch to development
branch.
2. list : To check the list of PRs, type gh pr list
NOTE: There are some flags also to filter the PR list by assignee, base branch, label, limit and state.
3. status : To check the status of the PR type gh pr status
4. view : To view the PR in the browser type gh pr view
. It will show the current PR. Also, it has options as number, url, branch.
5. checkout : Check out a pull request in Git.
Thanks for going through the article and I hope this guide interests you and helps you gain some knowledge.