Pragmatism in the real world

Command line access to GitLab & GitHub

I’ve always been a huge fan of the command line and have been using the gh command line tool to access GitHub for a while. My current client uses GitLab and I was delighted to discover that there is a glab CLI tool. As you can imagine, both tools do essentially the same thing: operate on GitHub/GitLab from the command line.

The two main uses of gh & glab that I have is creating and checking out Merge Requests/Pull Requests.

Creating an MR/PR

Creating an MR/PR is as easy as glab mr create. This provides interactive prompts to create MR with the option of opening an editor (vim in my case) to create the description. As with when you create an MR on the website, the editor is pre-populated with the information in the commits:

glab CLI tool creating a description for an MR

Once the title and description have been added you then submit or add metadata:

glab CLI tool when submitting an MR

The metadata section allows me to set the assignee, reviewer and milestone and then I submit.

I like this because I keep within the context of my development without swapping out to a browser.

Checking out an PR/MR

To review an MR, I will check it out locally and play with it. For OSS projects in particular where the PR is on a fork of the project, I find gh useful. Starting with gh pr list, I can see all the PRs waiting:

and then check one out based on the PR number with gh pr checkout {number}. The tool will then checkout the branching switch to it for me.

For client projects where we’re all working in a single repository, I tend to just use git checkout directly as our branch names are generally predictable, starting with the Jira ticket number and autocomplete then does its magic.

Opening in the browser

Another thing I do quite frequently is use gh repo view --web (or glab repo view --web) to open the current repository in my web browser. This also works for PRs with glab mr view --web (or gh pr view --web).

This is nice quick way to get to the right web page!

gh and glab are interchangeable

Helpfully, glab and gh have very similar commands, so it’s pretty easy to swap between them changing mr to pr as appropriate.

I highly recommend investing and using these tools. They do many more things in addition to the simple uses that I have.

Thoughts? Leave a reply

Your email address will not be published. Required fields are marked *