Github CLI: working with github workflow from terminal
Tags: githubcli, github, gh
Published: 2023-02-06 08:23:40

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](https://cli.github.com/) 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](https://github.com/cli/cli#installation) 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/69npqmb3g9upofg4e0fi.png)
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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i87ccky8r1mczpwralr0.png)
And here is a freshly created pull request
![created pr on github web page](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6pvhwv8bz8nxdjl56ots.png)
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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/douywsptcannnu4mbmp1.png)
And we can run our GitHub action workflow from the console.
![gh workflow run with parameters](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uw3cf2o5872g1xjda7ou.png)
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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/21vt2ke9m22fladhlphd.png)
And gh CLI is not limited to these actions. 
There is so much more you can do with Github CLI: managing [issues](https://cli.github.com/manual/gh_issue), [labels](https://cli.github.com/manual/gh_label) or drafting a new [release](https://cli.github.com/manual/gh_release) and all that straight from the console! The sky's the limit.
And there is repo with [a small example](https://github.com/ndebogory/gh_cli_test).