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!
Step 1 - Install the GitHub CLI
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 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:
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:
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!
Step 2 - Authentication
To authenticate yourself, punch in the following command:
gh auth login
Here's what you'll see:
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:
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:
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:
After I click the Continue
button, I see the following screen:
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 above screen tells me that the authentication process is complete!
When I switch to my Terminal
and press the Enter/Return
key, the CLI asks me to choose between the following two protocols that it'll use while communicating with the GitHub
server:
- HTTPS
- SSH
I'll choose the SSH
protocol here, but there's no harm in selecting the HTTPS
protocol either:
And it's done!
Let's execute the following command again and see what happens:
gh repo view pratikgchaudhari/vue-3-projects
As you can see in the above screenshot, the title of the repository along with the contents of its README
are displayed on the Terminal
.
The GitHub CLI
provides many more commands which I'll be covering in detail in a separate article in the future.
For now, this is it!
Top comments (0)