I tried Github CLIs...and I never open browser again!
Tags: beginners, productivity, github, codenewbie
Published: 2020-08-30 03:26:51

**Update**: I added #discuss, so please if anyone of you knows new features of Github CLIs, feel free to comment. Below, I found more cool things I could do with `gh`.

![https://cdn-images-1.medium.com/max/1600/0*_Gp8d1a15_03NZLb](https://cdn-images-1.medium.com/max/1600/0*_Gp8d1a15_03NZLb)

# Inspiration
- GitHub tools are all great, but sometimes, I get exhausted as I’m coding and have to switch from my terminal/text editor to do many clicks in the browser, just to create or view a PR.

- Luckily, on March 6th, 2020, GitHub released a new **cool GitHub CLI** to create PR/ Issue in your local terminal.

In this post, I will go over 1 main command that I usually daily and highly recommend: **`gh pr <command>`**.

---
# **Installment**
## **macOS**
1. Easy Install With brew: `$ brew install github/gh/gh`
2. Upgrade: `brew update && brew upgrade gh`

## **Windows**
Install `gh` via **[Scoop](https://scoop.sh/)**:

```shell
scoop bucket add github-gh https://github.com/cli/scoop-gh.git
scoop install gh
```

## **Linux**
For Linux and other platforms, please refer to this [GitHub page](https://github.com/cli/cli/releases/tag/v0.6.1) for different installment

# **Normal flow vs. new Github CLI**

**Old Process of creating a PR:**
  1. `(feat/login)$ git add .`

  2. `(feat/login)$ git commit -m "init skeleton code for login"`

  3. `(feat/login)$ git push origin feat/login`

  4. Open Github on browser

  5. Open Github project

  6. Click `Create a PR`

  7. Fill the title and body

**Now, let's see how many steps when we use `gh pr create`:**

  1. `(feat/login)$ git add .`

  2. `(feat/login)$ git commit -m "init skeleton code for login"`

  3. 
```sh
(feat/login)$ gh pr create
Enumerating objects: 9, done.
Counting objects: 100% (9/9), done.
Delta compression using up to 4 threads
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 444 bytes | 444.00 KiB/s, done.
Total 5 (delta 4), reused 0 (delta 0)
remote: Resolving deltas: 100% (4/4), completed with 4 local objects.
To github.com:calvinqc/trivin.git
   1c179cb..7953ecc  HEAD -> gh-testing
Branch 'feat/login' set up to track remote branch 'feat/login' from 'origin'.

Creating pull request for feat/login into master in calvinqc/trivin
? Title [WIP] Login API
? Body <Received>
? What's next? Submit
https://github.com/calvinqc/trivin/pull/1
```

## **Options**
Source from [Github CLIs](https://cli.github.com/manual/gh_pr_create): 
```sh
  -a, --assignee login   Assign people by their login
  -B, --base string      The branch into which you want your code merged
  -b, --body string      Supply a body. Will prompt for one otherwise.
  -d, --draft            Mark pull request as a draft
  -f, --fill             Do not prompt for title/body and just use commit info
  -l, --label name       Add labels by name
  -m, --milestone name   Add the pull request to a milestone by name
  -p, --project name     Add the pull request to projects by name
  -r, --reviewer login   Request reviews from people by their login
  -t, --title string     Supply a title. Will prompt for one otherwise.
  -w, --web              Open the web browser to create a pull request
```
### **Easy 1 line command:**
```sh
$ gh pr create -t "[WIP] Login API" -b "Init skeleton code for Login API" -r "calvinqc" -l "feat" -p "Roadmap" -B dev
```
$ 

If there’s one thing that I love about `gh pr create`, it is that it will **push + create a PR at the same time**.

## **List all PRs**

```sh
$ gh pr list
Pull requests for calvinqc/trivin
#2  [WIP] Register API  feat/register
#1  [WIP] Login API     feat/login
```
## **View a PR**
```sh
$ gh pr view 1
Opening https://github.com/calvinqc/trivin/pull/1 in your browser
```

## **Get status of all PRs**
```sh
$ gh pr status
Relevant pull requests in calvinqc/trivin
Current branch
  #1  [WIP] Login API     feat/login
   - Checks passing
Created by you
  #2  [WIP] Register API  feat/register
   - Checks passing
  #1  [WIP] Login API     feat/login
   - Checks passing
Requesting a code review from you
  You have no pull requests to review
```

## **Checkout a PR**

This is very similar to a regular branch checkout, but I don't have to checkout and then pull the code from that branch

```sh
$ gh pr checkout 1
```

# Let's connect
- https://linktr.ee/calvinqc