GitHub CLI: An Introduction

GitHub CLI: An Introduction

GitHub CLI brings GitHub to the terminal, it reduces context switching, helps you to focus, and enables you to write scripts and create your workflow from the terminal. Version 1.0 was released in September 2020 by the GitHub team to help developers create automated scripts for their workflows.

With GitHub CLI you can;

  • Connect to GitHub Enterprise Server (GHES) in addition to GitHub.com.
  • Create and Fork a repo.
  • Create, delete, upload, download, and manage your releases.
  • Create, review, and check the status of your PR(Pull Request).
  • Open, review, tag, create, and check the status of issues.
  • Create gist using a specific file or multiple files.
  • Make a request to GitHub API and the response.
  • Generate shell scripts for GitHub CLI commands.
  • Set up aliases for most used GitHub commands. And many more functionalities.

To be able to use the CLI, we definitely have to install it. Simply navigate to GitHub CLI, follow the installation guide for your operating system and you are ready to roll.

Clone A Repo

You can perform various repository tasks with the GitHub CLI, such as creating, cloning, and forking repositories. To clone a repository from GitHub use the command gh repo clone user/repo. User referring to the owner of the repo and repo referencing the name of the repo. Or simply copy it directly from your web browser.

ss1.png

ss2.png

ss3.png

Check or Create Issues

Now we can check for or create issues in our cloned repo with the gh issue create or gh issue list commands. GitHub CLI also supports interactive inputs so that you can create Issues with guidance without opening the browser.

ss4.png

There are currently no issues with this repo.

Now let's add a new branch to our repository by running git checkout -b "new_feature". Open your code editor, refactor your code, commit your changes, and push your changes with the git push --set-upstream origin new_feature command.

Create A Pull Request

You can create a pull request for your new branch created above with the gh pr create command. After you create the Pull Request, you can approve and review it from GitHub CLI. This feature becomes handy for scenarios where we need to analyze code and change PR’s status accordingly. It also provides the ability to approve the Pull Request if it meets specific criteria using CI/CD. Besides, you can merge the changes into the branch with the git pr merge command. The list of commands and features available with the GitHub CLI is quite long. I’ll leave them for you to discover. You can follow the manual for more information.

Conclusion

I’ve provided an introduction to GitHub CLI and it's basic features, it’s relatively easy to learn for anyone who knows the GitHub features. If you are still using the GitHub web portal, I feel it’s worth giving it a try and find out how it affects your productivity.