DEV Community

Nadia Debogori
Nadia Debogori

Posted on

Github CLI: working with github workflow from terminal

We all know and understand the usage and profit of git CLI. It works faster and sometimes you can do pretty complex stuff from the command line interface, things that UI just do not have the ability to complete (like cherry-pick). But it is not a very broad knowledge that there is also a CLI for GitHub like PullRequest creation, work with GitHub issues and literally almost every action that you may need to do.

But how can we get any profit from this knowledge? When you are working with git CLI after pushing a commit you do not need to switch to the browser with a risk of losing context. You can automate your actions through aliases or scripts. Working with a console is usually faster than with a graphic interface. And for me personally, it’s a time-saving action, because in my workflow with multiple branches I need to wait for on-push git-action completion then run a second git-action workflow with tests manually.

Installation is simple brew install gh or any other option available. Then follow auth instructions.

After that, we can create a new PR by running a command, inside our git repository for example. You do not need to add any parameters as branch name, because gh will automatically get the current branch name.
Start of pull request
If you have any PR-template in your git project, it will be used in your PR descriptions. There is a console step-by-step wizard and an option to move from console to a browser page.
terminal step-by-step wizard
And here is a freshly created pull request
created pr on github web page
We can check the statuses of GitHub actions that you've triggered via gh workflow view command or view run list for a certain workflow via gh run list --workflow workflow.yml
list of workflow runs
And we can run our GitHub action workflow from the console.
gh workflow run with parameters
Simply writing down a full command with lots of arguments could be frustrating, but with aliases, there is an opportunity to run things fast enough. There is a feature to create your own gh CLI aliases, so there is no need to remember all the names and arguments for workflows. I must point out that it is not a unix builtin alias, so there is a unified interface to create alias without being dependent on OS.
gh alias example
And gh CLI is not limited to these actions.
There is so much more you can do with Github CLI: managing issues, labels or drafting a new release and all that straight from the console! The sky's the limit.
And there is repo with a small example.

Top comments (1)

Collapse
 
ilyakaznacheev profile image
Ilya Kaznacheev

Never done that before this way. Thanks for a great article!