GitHub CLI
Updated: 03 September 2023
Setup
For MacOS the CLI can be installed with:
Once installed, you will need to log in using the CLI with:
Help
For help on any command, as usual, you can append --help
to the command you’re trying to use for more details
Working with Repos
PR functionality is contained under gh repo
Create a Repo
To create a repo you can use:
And then follow the prompts
Clone a Repo
To clone a repo you can use the gh repo clone
command with the name of the repo, for example to clone the repo that this file is in:
Working with Pull Requests
PR functionality is contained under gh pr
Create a PR
You can create a pull request using:
If you don’t give it any args with the required data then the CLI open the interactive menu to select any required data
Some of the params that I use frequently when creating a PR are --title
, --labels
, and --reviewer
A PR with the above may look like so:
A draft PR can also be created by appending --draft
to an PR related command, e.g.
Or
List PRs
You can list PRs using
Additionally, you can do things like searching and the like using the various flags, e.g. to check for PRs with a specific labels:
Or a more complex version which looks for only closed PRs and limits the output to 100
Which will get PRs that have both the feature
and cool
label
Working with JSON
Each of the CLI commands that output data let you get the data in JSON format along with specific fields
To use the JSON output, append the --json
flag followed by a list of the JSON fields you’d like to see
The following is an example that uses one of the PR commands above with the JSON output with author and pr labels