Released in beta last February, GitHub CLI has now reached version 1.0. According to GitHub, you can use GitHub CLI for your entire workflow from issues to reviews to releases. In addition, you can script the GitHub API to automate any available action.
A typical workflow with GitHub CLI starts with listing open issues by executing gh issue list
or gh issue list --assignee <name>
. The gh issue
command provides a number of options to filter its output. For example, you can show only critical
issues with gh issues list --label "critical"
or closed
issues with gh pr list --state closed
.
When you are done fixing an issue, you can create a pull request with gh pr create
, which will prompt you to provide all required information.
To approve the pull request, a coworker could run gh pr checkout <#PR>
, display the diff using gh pr diff
, and provide a review using gh pr review
. Actually, at this early stage, GitHub CLI support for reviewing PRs is minimal. Specifically, it does not allow you to write comments inline, although this feature is on GitHub CLI roadmap along with the ability to edit issues and pull requests.
The command gh pr checks
runs all tests to make sure they pass before approving the PR, which can be done with gh pr review --approve
. After this step, the PR can be merged with gh pr merge
.
Finally, once you made sure everything is working as expected, you can create a new release using gh release create <tag>
. gh release
includes many options which enable integrating it with your CI/CD workflow. For example, you can add release notes, mark a release as a pre-release, download or upload assets to a release, and so on.
GitHub CLI also allows you to create new issues using
gh issue create -t "Pull request title" -b "Pull request body"
.
Other useful features in GitHub CLI enable creating, editing, listing, and viewing gists, both public and private, using gh gist
.
As mentioned, GitHub CLI gives access to GitHub API with the gh api
command. This makes it possible to script whatever custom workflow you could require using the full GitHub API v3. For example, you can list tags for a repo running:
gh api repos/account/repo/tags
As mentioned, GitHub is at work to add new features to GitHub CLI, a process where the GitHub community can play a significant role. The company says version 1.0 includes more than 100 community contributions and that many new features were based on community feedback during the beta process.
GitHub CLI is available for Linux, macOS, and Windows.