DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Cover image for Github CLI - bring Github to the command line
Srebalaji Thirumalai
Srebalaji Thirumalai

Posted on • Originally published at gitbetter.substack.com on

Github CLI - bring Github to the command line

This post was originally posted in the newsletter GitBetter. If you are interested in leveling up your game in Git, you can subscribe to it.

Github CLI is one of the useful tools you can start using right away if you are a very active Github user.

You can visit the repo here.

This is still in beta but you can still use it. It brings PRs, issues, and other useful features of Github to the command line.

I will cover some commands that I find very useful. And you can also play around with the tool.

Listing Pull requests

You can list all the PRs of the repo.

gh pr list

There are options for filtering PRs with the assignee, base branch, labels.

Examples :

gh pr list --label "WIP, help" // List PRs with the provided labels

gh pr list --base "master" // List PRs with master as base

gh pr list --assignee "john" // List PRs with the respective assignee

Creating a Pull request

Creating a PR is very easy with CLI. This can make you really productive.

gh pr create

The above command is a very basic option. This will create a PR with the _ master _ as the base branch and the _ current branch _ as the target branch.

There are other options as well for changing the base branch, labeling, assigning people, etc

Examples :

gh pr create --base develop // Here develop is the base branch

gh pr create --title "PR title" // Create a PR with title

gh pr create --reviewer "john, arya" // Assign reviewers

gh pr create --label "prod, help" // Assign labels

View Pull request change

gh pr diff <PR number / url>

Example
gh pr diff 3

The above command will show the diff of the respective PR. This will come in handy if you are looking for small changes in PR.

Creating an issue

Creating a simple issue from the CLI will come in handy often.

gh issue create --title "Search not working" --body "Search in main dashboard is not working"

The above command will create a new issue with the respective title and body.

There are like other useful options too

Examples

gh issue create --label "help, priority" // You can assign multiple labels

gh issue create --assignee "john, arya" // You can assign people

Listing issues

gh issue list

This will list all issues.

Examples

gh issue list --label "help, priority" // List issues by labels

gh issue list --assignee "john, arya" // List issues by assignees

gh isssue list --author "srebalaji" // Lists issues by people who created the issue

Creating gist

This is one of my favorites. You can create a public or private gist from the command line itself.

gh gist create main.js

The above command will create a private gist with the given file.

By default, gists are made private.

Other options,

gh gist create --public main.js // Creating a public gist

gh gist create main.js -d "NodeJS example" // Creating a gist with a description

gh gist create main.py copy.py home.py // Creating a gist with multiple files

Github CLI is a very useful command-line tool you can use. I have been using it for a couple of weeks and I can say it’s very useful. Of course, there are some hiccups but I believe it will be resolved in the upcoming versions.

Highly recommended if you are using Github often.

Thank you for reading :)

This post was originally posted in the newsletter GitBetter. If you are interested in leveling up your game in Git, you can subscribe to it.

Top comments (0)

Why You Need to Study Javascript Fundamentals

>> Check out this classic DEV post <<