Getting Started With GitHub CLI

Posted by An IoT Odyssey on March 21, 2022 · 3 mins read

One of the most powerful tool in our toolbox as a developer is the ability to version control our work. This enables us to work in an agile environment where we can make changes with more confidence.

I personally version controls a lot of my works. These works are not just limited to source codes but anything that can change over time e.g. blog contents, ideas and designs, proof of concept projects.

There are many version control platforms out there (GitHub, GitLab, BitBucket).

For myself, I am using GitHub. My workflow generally involves creating a remote repository on GitHub (up till now this has been done via a browser), then create a local repository on my development machine by cloning the remote repository (by the way, if you are not familiar with some of these terminologies, have a read of this About Git). Yes there is a bit of context switching involved so I thought this would be a good opportunity for us to have a look at the GitHub CLI tool.

Installing GitHub CLI

There are a few ways we can install GitHub CLI which also depends on our development environment. I am currently using Windows so the easiest way is to download the installation package from the releases page under the assets section. As of writing, the latest release is GitHub CLI v2.6.0) and for a Windows x64 system, we can download gh_2.6.0_windows_amd64.msi.

Once installed, we can verify the installation by running the command gh --version.

Check GitHub CLI version

Authenticating GitHub CLI

Next, we will need to authenticate with our GitHub account by running the command gh auth login. The people at GitHub has made the process really simple so just follow the instructions. Note in the example below we used a personal access token instead of password to authenticate.

GitHub CLI login

Creating a new repository

There’s two methods of creating a new GitHub repository, an interactive method and a non-interactive method.

To use the interactive method, run the command gh repo create. We will then be guided through the options needed for the new repository.

To use the non-interactive method, run the command gh repo create but this time explicitly providing the options with the create command. For example: gh repo create GitHubCLIDemo -d "Create command demo" -g VisualStudio -l MIT --public -c. For more help on the available options, have a look at the the gh repo create page.

Create new GitHub repository

There’s a lot more we can do with GitHub CLI but for me, just being able to create a new repository on GitHub and clone it to our local environment without the need to switch to a browser is enough to add GitHub CLI to my development toolkit.