GitHub CLI 1.0 was released on Sept 17, 2020
GitHub, the popular Git Provider has created a command-line tool that allows its users to access
_GitHub_
without leaving their terminals!
In this post, I’ll walk you guys through the process of setting up the GitHub CLI on your local machine.
So, let’s start!
Before you can start using the GitHub CLI, you must install it on your local machine.
Installing on Mac
If you’re using macOS,
you can install it using Homebrew, like so:
brew install gh
Here’s a gif to give you a better idea:
Installing the GitHub CLI. Image Credit: Pratik Chaudhari
Installing on Linux
For Linux
users, too, Homebrew should work just fine.
Although, if you’re using a Linux distro that isn’t officially supported by GitHub,
you’ll have to rely on the community-maintained versions of the CLI.
Instructions for installing the CLI on such distros can be found here.
Installing on Windows
If you’re a Windows
user, you can use Chocolatey to install the CLI, like so:
choco install gh
Once installed, you can access it using the gh
command, like so:
gh
Here’s what the above command will output:
Output after firing the ‘gh’ command. Image Credit: Pratik Chaudhari.
Now that the CLI has been installed and is accessible via the Terminal
, let’s do something interesting using the CLI, like viewing a GitHub repository:
gh repo view pratikgchaudhari/vue-3-projects
The above command is supposed to display all the info of the vue-3-projects
repo created by its owner pratikgchaudhari
, i.e., me.
But here’s what we get instead:
Output of ‘gh repo view pratikgchaudhari/vue-3-projects’ command. Image Credit: Pratik Chaudhari.
The GitHub CLI
requires you to authenticate yourself with your GitHub credentials before doing anything else with it!
And that brings us to our next step!
To authenticate yourself, punch in the following command:
gh auth login
Here’s what you’ll see:
Output of ‘gh auth login’ command. Image Credit: Pratik Chaudhari.
The GitHub CLI
is asking you whether you want to sign in using your account on GitHub.com, which is free for all users, or whether you want to use the GitHub Enterprise account (most probably owned by your employer or maybe just you).
Since I don’t have an enterprise account, I’ll proceed with my GitHub
account.
Here’s what I see after selecting the said option:
Output after selecting the ‘GitHub.com’ option. Image Credit: Pratik Chaudhari.
Since I don’t have an authentication token
(yet), I’ll choose the Login with a web browser
option.
Once I choose the said option, the CLI provides me with a one-time
code:
Output after selecting the ‘Log in with a web browser’ option. Image Credit: Pratik Chaudhari.
I copy the one-time
code provided by the CLI and press the Enter/Return
key.
As expected, a browser window opens where I need to paste the one-time
code that I just copied:
The browser window where the ‘one-time’ code must be pasted. Image Credit: Pratik Chaudhari.
After I click the Continue
button, I see the following screen:
The OAuth authorization interface for ‘GitHub CLI’ in browser. Image Credit: Pratik Chaudhari.
Basically, I’m being prompted to authorize the GitHub CLI
to access various resources from my GitHub account.
So, I’ll grant it the access that it requires by clicking on the Authorize github
button. Here’s what I see next:
The OAuth authorization success interface in browser. Image Credit: Pratik Chaudhari.
The above screen tells me that the authentication process is complete!
#github #programming #web-development #developer