GitHub CLI in my day to day workflow

I hate context switching in general and that is why I try very hard not to have to switch tooling for as long as I can. In particular, when it comes to source code management, I try to do it all from the terminal.

At DuckDuckGo we use GitHub as our source code management tool. And our day to day involves looking at issues, creating, reviewing, approving PRs, etc. I use Git from the command line and so, I do not like having to lift my hand off of the keyboard and reach out to the mouse just to go to GitHub to eg. review/search for some PR, or take a look at some issue. For that I use GitHub CLI

Apart from the comprehensive list of commands GH CLI has, it allows to create aliases, which is a bonus to my productivity.

These are some of the automations that help me on a daily basis.

Checkout PR(s) that I need to review

GitHub alias:

$ gh alias set co --shell 'id="$(gh pr list -L100 --assignee @me| fzf | cut -f1)"; [ -n "$id" ] && gh pr checkout "$id" && gh pr checks'

From the command line I just execute gh co and it bring the list of all the open PRs assigned to me. Selecting one will automatically check it out locally so that I can start reviewing.

Quickly check PR diff

GitHub alias:

$ gh alias set diff --shell 'id="$(gh pr list -L100 | fzf | cut -f1)"; [ -n "$id" ] && gh pr diff "$id"'

Some times I just want to take a look at the PR diff, without leaving the terminal. Running gh diff will display a list of open PRs, selecting one will show the diff.

image

One awesome thing is that gh respects the PAGER environment variable, so you can use git-delta for that.

$ gh config set pager 'delta -s'

The result is something like this.

image

Open PR in Web Browser

GitHub alias:

$ gh alias set prv --shell 'id="$(gh pr list -L100|fzf|cut -f1)"; [ -n $id ] && gh pr view --web "$id"'

Commenting on a PR I am reviewing is something I do in the web browser. But opening any PR is normally 4-5 clicks away. Running gh prv displays a list of PRs so that I can quickly select one that will automatically open in the browser.

The above are only some of the automations that I have. I have other automations for GH CLI that concern our internal tooling, eg. directly open the internal task referenced in a given PR…and many more.

I hope this article has sparked your curiosity to check GH CLI out, I find it a really great tool.