# Getting Started With the Github CLI

> GitHub CLI 1.0 was released on Sept 17, 2020

> [GitHub](https://github.com/), the popular [Git](https://git-scm.com/) 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](https://cli.github.com/) 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](https://formulae.brew.sh/formula/gh#default), like so:

```
brew install gh
```

Here’s a gif to give you a better idea:


![Installing the GitHub CLI. Image Credit: Pratik Chaudhari](https://cdn.hashnode.com/res/hashnode/image/upload/v1606312058074/nxymHiHID.gif)

> #### Installing on Linux

For `Linux` users, too, [Homebrew](https://formulae.brew.sh/formula/gh#default) should work just fine.

Although, if you’re using a [Linux distro](https://en.wikipedia.org/wiki/Linux_distribution) 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](https://github.com/cli/cli/blob/trunk/docs/install_linux.md).

> #### Installing on Windows

If you’re a `Windows` user, you can use [Chocolatey](https://chocolatey.org/) 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.](https://cdn.hashnode.com/res/hashnode/image/upload/v1606312330133/lmdjnJrSK.gif)

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](https://guides.github.com/activities/hello-world/):

```
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.](https://cdn.hashnode.com/res/hashnode/image/upload/v1606312574109/M3lDoVj0A.gif)

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:


![Output of ‘gh auth login’ command. Image Credit: Pratik Chaudhari.](https://cdn.hashnode.com/res/hashnode/image/upload/v1606314420261/YcCC1J65f.png)

The `GitHub CLI` is asking you whether you want to sign in using your account on [GitHub.com](https://github.com/), which is free for all users, or whether you want to use the [GitHub Enterprise](https://github.com/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.](https://cdn.hashnode.com/res/hashnode/image/upload/v1606314545518/A4jyz4srJ.png)

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.](https://cdn.hashnode.com/res/hashnode/image/upload/v1606314654100/BHM98IByb.png)

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.](https://cdn.hashnode.com/res/hashnode/image/upload/v1606314752114/wvgrBl2ToS.png)

After I click the `Continue` button, I see the following screen:


![The OAuth authorization interface for ‘GitHub CLI’ in browser. Image Credit: Pratik Chaudhari.](https://cdn.hashnode.com/res/hashnode/image/upload/v1606314825078/FYREOy7S_.png)

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.](https://cdn.hashnode.com/res/hashnode/image/upload/v1606314915179/9acaLW87h.png)

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:

1. HTTPS

2. SSH


![The ‘Terminal’ prompting user to select a communication protocol. Image Credit: Pratik Chaudhari.](https://cdn.hashnode.com/res/hashnode/image/upload/v1606315034246/y6K3XPA_P.png)

I’ll choose the `SSH` protocol here, but there's no harm in selecting the `HTTPS` protocol either:


![Output after selecting the SSH protocol. Image Credit: Pratik Chaudhari.](https://cdn.hashnode.com/res/hashnode/image/upload/v1606315102887/JRA4p_Q-E.png)

And it’s done!

Let’s execute the following command again and see what happens:

```
gh repo view pratikgchaudhari/vue-3-projects
```


![Output of ‘gh repo view pratikgchaudhari/vue-3-projects’ command. Image Credit: Pratik Chaudhari.](https://cdn.hashnode.com/res/hashnode/image/upload/v1606315181697/DiMh9xDZy.png)

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!

