How to use Github CLI in 7 commands

thomasvanholder

thomasvanholder

Posted on November 4, 2021

How to use Github CLI in 7 commands
  1. Open project in Github
  2. List all issues
  3. Create new issue
  4. List all PRs
  5. Check PR status
  6. Merge PR into main
  7. Switch between branches

Github CLI installed?
Check by running gh version

Or install Github CLI


1. Open project in Github

Open the github homepage of the current project in the browser.

gh browse
Enter fullscreen mode Exit fullscreen mode

Github CLI's response:

Opening github.com/repo/my-repo in your browser.
Enter fullscreen mode Exit fullscreen mode

2. List all issues

Return all outstanding issues in the repository.

gh issue list
Enter fullscreen mode Exit fullscreen mode

Github CLI's response:

Showing 3 of 3 open issues in repo/my-repo

#178  bug when downloading pdf            about 3 minutes ago
#166  refactor stripe api call            about 2 days ago
#126  depreciate pacakge                  20 days ago
Enter fullscreen mode Exit fullscreen mode

3. Create new issue

Did you find a new bug?
Add something as a to-do for later on Github Issues. The CLI will prompt you a few questions.

gh issue create
Enter fullscreen mode Exit fullscreen mode

Github CLI's response:

Creating issue in repo/my-repo

? Title bug when downloading pdf
? Body <Received>
? What's next? Submit
https://github.com/repo/my-repo/issues/178
Enter fullscreen mode Exit fullscreen mode

4. List all PRs

Retrieve an overview of all PR in the repository.

gh pr list
Enter fullscreen mode Exit fullscreen mode

Github CLI's response:

Showing 3 of 3 open pull request in repo/my-repo

#170  feat/stripe-checkout
#142  feat/vitally-api
#139  bug/profile-responsiveness
Enter fullscreen mode Exit fullscreen mode

5. Check PR status

To find out if the PR passed the automated testing suite.

gh pr status
Enter fullscreen mode Exit fullscreen mode

Github CLI's response:

Relevant pull requests in repo/my-repo

Current branch
  #177  new-feature [new-feature]
  āœ“ Checks passing
Enter fullscreen mode Exit fullscreen mode

6. Merge PR into main

A useful shortcut to easily delete a branch from both Github and your local enviroment.

2 options:

  • From the local main branch

Merge a PR into the main branch by specifying the PR number.

gh pr merge 177
Enter fullscreen mode Exit fullscreen mode
  • From the PR branch

No need to specific the PR number.

gh pr merge
Enter fullscreen mode Exit fullscreen mode

Github CLI's response:

? What merge method would you like to use? Create a merge commit
? Delete the branch locally and on GitHub? Yes
? What's next? Submit
āœ“ Merged pull request #177 (new-feature)
āœ“ Deleted branch new-feature
Enter fullscreen mode Exit fullscreen mode

7. Switch between branches

This CLI command is based upon a popular extension.

Install the extension

gh extension install mislav/gh-branch
Enter fullscreen mode Exit fullscreen mode

Run the extension.

gh branch
Enter fullscreen mode Exit fullscreen mode

Move across branches with up and down arrow. Hit enter to select the branch.

Github CLI's response:

  feat/stripe-checkout             6 weeks ago
  feat/postmark-integration        2 weeks ago
> new-feature                      25 hours ago
  bug/profile-responsiveness       2 hours ago
  4/4
Enter fullscreen mode Exit fullscreen mode
šŸ’– šŸ’Ŗ šŸ™… šŸš©
thomasvanholder
thomasvanholder

Posted on November 4, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

How to use Github CLI in 7 commands
github How to use Github CLI in 7 commands

November 4, 2021