Mateusz Jędrzejewski is a DevOps Engineer at Nethermind. In this post, he reviews Github’s new command line tool, which brings pull requests, issues, and other GitHub concepts to the terminal next to where you are already working.
The Github CLI v 1.0 has been announced on the 17th of September this year and I’ve just jumped straight into exploring and playing with this release. It comes with many new features that can be helpful for any person using Github on a daily basis. Personally, I am a fan of CLI tools and I use them wherever possible. I believe that this release will settle in my terminals for good. Let us see what it has to offer and check some of the most useful commands. The full documentation containing all available commands can be found here.
gh alias
One of the most useful features of the CLI. Is very helpful when we want to create shortcuts for various gh
commands and have the ability to combine them. By using gh alias
you can either set an alias, delete it or display a list of current aliases. We can make the alias even more flexible by passing command-line arguments such as $1
, $2
, and so on. For example, you can create an alias which will display a list of issues by a label:
gh alias set ibl 'issue list –label="$1"'
gh repo
The quick ability to clone a Github repository by providing the OWNER/REPO names only. We need to use -- --recursive
flag if we want to clone the repository recursively.
Like this:
gh repo clone nethermindeth/nethermind -- --recursive
It might be also useful to set an alias for this so that we can re-use this command in the future
gh alias set nethermind 'repo clone nethermindeth/nethermind -- --recursive'
which then can be used by simply typing
gh nethermind
gh repo
comes with the ability to create a repo by saying gh repo create
and then going through the dialog or by passing arguments to the command. Forking the repository withgh repo fork OWNER/REPO
can be a handy tool as well.
gh release
The gh release
comes with a set of very nice commands which can enhance your CI/CD experience by automating your processes of release creation. We can for example quickly create a release with notes uploaded directly from the changelog, mark it as a pre-release and give it some title:
gh release create 1.8.106 -p -F changelog.md -t v1.8.106
We can also quickly download, upload specific assets to the releases by saying:
gh release download 1.8.105 -p 'nethermind-linux-*'
and it will download only those assets that match a glob pattern of nethermind-linux-*
gh pr
gh pr
is designed to make life easier when managing the pull requests. With these commands, we can have a full overview of the PR somebody created or we can create our own. We can close, review, reopen, and perform many other actions that we normally do through the web.
Let’s display a list of a current PR’s outstanding in the repo:
gh pr list
checkout to the one we would like to work on:
gh pr checkout 2303
and see whether the required checks from Github Actions have passed, there is a nice overview of each job including the running time and direct links.
gh pr checks 2303
We can also have a nice overview of the PR by typing gh pr status
.
What I also really like is the possibility to create a new PR with gh pr create
and passing arguments of our need mentioned here.
It is very useful when it comes to automating the PR creation process.
gh issue
The gh issue
the command is great when you need to quickly create, close, or simply view the issue you would like to work on. For example, we can list the issues that are assigned to us to see what we would like to take today with:
gh issue list -a matilote
Then view the issue to see more details:
gh issue view 1849
To have an overview of the status of the current issue that was either assigned to us, opened or we were mentioned in one of them.
gh issue status
gh gist
The gh gist
command allows the user to work on the Github gists. The one I find the most useful for myself was the gh gist create filename.sh -d 'Filename description'
which creates a gist with its relevant description. We can also make the gist public
by adding -p
or --public
flags.
gh config
It simply allows the user to manage their gh
configuration. Nothing much is going on here.
gh auth
Probably used the least. It provides options to authenticate the user, login, logout refresh, or view the authentication status.
gh api
The gh api
command allows us to perform Github API HTTP requests and receive responses. For those who prefer graphql
(grants access to Github API v4) queries it's also available. To display a list of tags for a given repo you can type something like this:
gh api repos/nethermindeth/nethermind/tags
You can use any available endpoint of Github API v3 e.g. to get the list of repository runs
gh api repos/nethermindeth/nethermind/actions/runs
You can then use the power of the most popular JSON parsing command-line tool jq
and grab everything you need from the API responses.
Conclusion
The fact that this project is community-driven is amazing. The new Github CLI is quite promising and is definitely able to make the life of devs easier, especially by setting up aliases for multiple commands with some additional arguments that the user can pass. To make our work more efficient I would love to see gh actions
commands in the future, that would allow the user to perform actions such as viewing the status of currently running GH Actions runs (something like gh pr checks
output) and manipulating them by cancelling or rerunning. I found the gh release
commands very useful for the CI/CD processes. The gh api
command can be easily replaced with simple `curl` requests, as it is a little bit simpler, I use it for tracking the release assets downloads over time. I’ve already made some aliases that will surely become a good companion for my daily DevOps tasks.
— — — —
Keep up to date with all the latest Nethermind news by following us on our socials:
- Newsletter Signup: http://nethermind.io/newsletter
- Twitter — https://twitter.com/nethermindeth
- LinkedIn — https://www.linkedin.com/company/nethermind
- GitHub: https://github.com/NethermindEth/nethermind
- Discord — https://discord.gg/XUz8Bd
- Gitter — https://gitter.im/nethermindeth/nethermind
- Email — hello@nethermind.io