Increase your productivity with the Github CLI
Tags: github, cli, productivity, programming
Published: 2024-02-26 22:18:13

If you use Github on a daily basis and still don't know about the Github CLI, I recommend you to keep reading this article. Today we are going to learn how to increase our productivity and quality of life when working with issues, pull requests, actions, and more!

## Table of contents
- [Instalation](#instalation)
- [Authenticating](#authenticating)
- [Repositories](#repositories)
- [Issues](#issues)
- [Pull requests](#pull-requests)
- [Aliases](#aliases)
- [Actions](#Actions)
- [Learning more](#learning-more)
- [Extensions](#extensions)
- [Conclusion](#conclusion)

## Instalation

Before we start, we need to install the CLI to be able to use it, as there are many operating systems in this beautiful world, I will leave here a link to the [installation guide](https://github.com/cli/cli?tab=readme-ov-file#installation) from Github itself.

With the tool installed, we can check the version with the command:

```bash
gh --version
```

## Authenticating

After installing, we need to authenticate to be able to enjoy the tool, this is done with the command:

```bash
gh auth login
```

To verify that you are indeed logged in, run this command:

```bash
gh auth status
```

A message saying that you are logged to Github in your account should appear.

# Repositories

With the Github CLI, we can clone, fork, list, view a repository, and much more.

Let's say we would like to see all our repositories, we can use the `gh repo list` command.

![A table showing all my repositories](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/awbcmjlrbxq4we0gu6hn.png)

This is the command output, a very friendly little table that shows the names, descriptions, and some other information of all my repositories, note that it says it is showing 30 of 31, this is because this command only shows repositories in which I am the owner, the 31st is a repository that I am only a contributor, so it is not shown.

We can also create a repository, with `gh repo create`, this command helps a lot to simplify the process of creating and setting up a completely new repository:

![A questionary asking for the name, owner, description, visibility and some other helpful stuff](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cfi213e2jgv7cax7rzm5.png)

Cloning is also simplified, we can do it the way we are already used to with git, using the repository URL:

![Successfully cloning using the url](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oah1z2niiyzeldajjwn4.png)

Or even better, doing `gh repo clone OWNER/REPO`:

![Successfully cloning using the OWNER/REPO syntax](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e5l7lmffskrugujz0l8t.png)

With `gh repo fork`, the syntax is the same.

With this command, we can also archive, delete, rename, and sync repositories and more!

## Issues

We work a lot with different issues daily, the CLI also makes our life easier in this regard, removing the need to leave the terminal to open/view/list/comment etc.

As expected, to create an issue, we use `gh issue create`:

![Questionary asking the issue's title, body and if you want to submit, continue in browser or cancel](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j0p5f9n33xsm65i8atr3.png)

Similarly, if we want to see the issues created, we use `gh issue list`:

![A list of issues showing labels, titles and when it was created](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2prm92fem4j5efxirbgm.png)

If we want to see only issues with a specific label, we can use the `--label` flag, for example, to see only issues with the "bug" label, we can do `gh issue list --label=bug` (in my case the only issue is already a bug, but it works!).

To get more information about a specific issue (for example, the real issue instead of just the title and label), we use the `gh issue view <issue_number>` command:

![Terminal showing the issue title, body and status](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6bdb7ohbtcc4xxh9wpz3.png)

In this case, the information is easily understood by the terminal itself, however, sometimes we have larger media or texts and seeing the issue through github would be better, for that we can use the `--web` flag.

![This way you see the issue in the browser](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c6ts9mc3p0h465omhmx6.png)

We can comment on open issues using the `gh issue comment <issue_number>` command:

![Questionary asking the comment content and if you want to post it or not](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/brm3rg85mexoggxhsdyg.png)

Additionally, it is also possible to close, reopen, delete, pin issues and much more.

## Pull requests

By far, what I like most about using the CLI is how much it simplifies working with pull requests, for example, let's say we have a new branch with changes already committed and now we want to create a PR for the repository, instead of going through the hassle of uploading a new branch and creating it through the site, we can simply do `gh pr create`.

![Questionary asking the pr's title body and if you want to submit](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tg34o27ypp8tp7kf2i6s.png)
If we need to add some kind of media, we can simply continue in the browser, but all the information will already be there.

Just like in issues, we can also use `gh pr list` and `gh pr view`, to list all pull requests and see more details about a specific one respectively.

Imagine that someone has just opened a PR in the repository, and now? how to test the code? It is possible to check out locally with `gh pr checkout <pr_number>`, so your git will create a new branch in your local repository, with all the changes presented in the pull request:

![It creates a new branch with the code presented in the pr](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/poxr0vpxiobd4b73snvh.png)

It is also possible to comment on a pr with `gh pr comment <pr_number>`:

![Same as commenting on an issue](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kweh5itu4fvqybq1tg4d.png)

Now let's say you do have checks configured for new pull requests, such as linters or automated tests, you can check the status of a specific pr with `gh pr checks <pr_number>`:

![Showing one check of aa linter that passed and took 2 min and 19 seconds](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/471npomjw3phn7e8rmyh.png)

In addition, we can also review, mark a pull request as ready for review, close, reopen, merge, and more, all through the terminal.

## Aliases

Like any terminal tool, it's always good to create aliases for commands you use frequently, we can do this using the `gh alias set` command. For example, let's create an alias called "bugs", which will show us only the issues with the "bug" label, to achieve this just type in the terminal:

```bash
gh alias set bugs 'issue list --label=bug'
```

Now we can at any time type "gh bugs" in the terminal and see all related issues :)

Additionally, we can delete an existing alias with `gh alias delete <name>` or view all created aliases with `gh alias list`.

## Actions

If you use Github Actions, another power of the CLI is the ability to control and view relevant information directly in the terminal, with `gh run` and `gh workflow`, the difference is that `workflow` refers to the files and `run` the runs that the actions have already had.

To list all recent runs, we use `gh run list`:

![list of runs showing their titles, status, time taken and workflow](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ihkimj7bitgril2f5ofv.png)

We can also see details of a run or jobs using `gh run view`:

![Showing more info of a run, like its individual jobs](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o1c2czuof5vm8fjzxteu.png)

The same goes for `workflow`, however, with this subcommand we can also use `enable` and `disable`, to enable and disable a specific workflow file.

If your workflow receives the `workflow_dispatch` event, it is possible to activate it manually with the command:

```bash
gh workflow run
```

# Learning more

We only scratched the surface of what the Github CLI is capable of, some of the other features that we can manipulate with this tool include: releases, projects, organizations, labels, gists, Github Actions variables, and more!

To better understand how it can help you in your day-to-day life as a developer, I recommend exploring the existing commands with `gh help`:

![This command shows all commands and a small description of what they do, as well as your aliases and what command they represent](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/99qqeze2pgnp1ffcwlxw.png)

Note that our alias commands also appear here, which is a nice addition.

If our doubt is about a specific command or subcommand, we can always use the syntax `gh help <command> <subcommand>`, for example:

![A long description of what the command pr create does](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s07h4e6y4e9ucak31bz2.png)
![Flags for that command](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tsmlvltw89j3fa87u80z.png)
![Examples and where to learn more](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s6jvvj6leph8q3k32ryh.png)

We got a super detailed description of exactly what this command does, the available flags, the aliases, examples, and more information!

## Extensions

Every good tool needs to have extensions made by the community, and here it is no different, we have several official and community-made extensions to further boost your CLI. To start, use the command:

```bash
gh extensions browse
```

![A list of all extensions with a preview of their readme in the right](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4dm43vq8pc08s5bemhre.png)

Here we can see all the extensions, see their repositories, and install them if we want, if you want to find a specific extension, you can use the `search` subcommand:

![Here i am searching for a star extension](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a2xg2lksfwj4yf7u7h6d.png)

Installed an extension and now decided you don't want it anymore? No problem, just use the `gh extensions list` command to see all installed extensions and `gh extensions remove` to remove one of them:

![Successfully removing the dash extension](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/flkkyv6hstpaazltu7pr.png)

## Conclusion

I hope you enjoyed this article! I personally use this tool daily and it has helped me a lot, especially in open source projects, I hope it can help you too.

If you want to read more about it, here is the [official manual](https://cli.github.com/manual/).

If you have any questions, suggestions, or feedback, feel free to leave a comment, I will be happy to answer, thank you for reading!