GitHub CLI - GitHub and command line in 2024

4 min read
Last updated: Feb 25, 2024

With GitHub CLI, you can: Run your entire GitHub workflow from the terminal, from issues through releases; Call the GitHub API to script nearly any action, and set a custom alias for any command, and Connect to GitHub Enterprise Server in addition to GitHub.com.

GitHub CLI works with repositories hosted on GitHub Enterprise Server 2.20+.

Through terminal, it reduces context switching, which helps to focus, and it’ll be easier to script and create workflows. It is available to download on Windows, macOS, and Linux.

github-cli-1

Commands

Installation:

  • In macOS gh is available via :
  • Homebrew

    • brew install gh
    • brew upgrade gh
  • MacPorts

    • sudo port install gh
    • sudo port selfupdate && sudo port upgrade gh
  • Linux, follow Docs
  • Windows, gh is available via scoop, Chocolatey, and as downloadable MSI.
  • scoop

    • scoop bucket add github-gh https://github.com/cli/scoop-gh.git
    • scoop install gh
  • Chocolatey

    • choco install gh
    • choco upgrade gh

Authentication:

  • Run gh auth login to authenticate with your GitHub account. gh will respect tokens set using GITHUB_TOKEN.
  • GitHub CLI supports GHES 2.20 and above. To authenticate with a GitHub Enterprise instance, run: gh auth login --hostname <hostname>

    • You will be prompted to either authenticate using your browser, or to paste a token.
$ gh auth login
# => do an interactive setup

$ gh auth login --with-token < mytoken.txt
# => read token from mytoken.txt and authenticate against github.com

$ gh auth login --hostname enterprise.internal --with-token < mytoken.txt
# => read token from mytoken.txt and authenticate against a GitHub Enterprise Server instance

View authentication status

gh auth status [flags]

Setting your git protocol

gh config set git_protocol { ssh | https }

To clone the repository

~/$ gh repo clone https://github.com/cli/cli
Cloning into 'cli'...
remote: Enumerating objects: 99, done.
remote: Counting objects: 100% (99/99), done.
remote: Compressing objects: 100% (76/76), done.
remote: Total 21160 (delta 49), reused 35 (delta 18), pack-reused 21061
Receiving objects: 100% (21160/21160), 57.93 MiB | 10.82 MiB/s, done.
Resolving deltas: 100% (16051/16051), done.

To find PR status and Open issues you need to work on

~/$ gh pr status
Current branch
  #12 Remove the test feature [user:patch-2]
   - All checks failing - Review required

Created by you
  You have no open pull requests

Requesting a code review from you
  #13 Fix tests [branch]
  - 3/4 checks failing - Review required
  #15 New feature [branch]
   - Checks passing - Approved

~/$
# Viewing a list of open issues
~/$ gh issue list

Issues for owner/repo

#14  Update the remote url if it changed  (bug)
#14  PR commands on a detached head       (enhancement)
#13  Support for GitHub Enterprise        (wontfix)
#8   Add an easier upgrade command        (bug)

~/$

To create your pull request

gh pr create

A teammate can check your pull request

gh pr checkout [request number]

To view the differences

gh pr diff

To review the change

gh pr review

To check passed test(s) after the pull request is approved

gh pr checks

To merge it directly

gh pr merge

For your next release

gh release create [tag name]

To create aliases

gh alias set

To access the GitHub API directly

gh api

To share your aliases with a GitHub gist

gh alias list | gh gist create

Do refer Online manual for more information. GitHub CLI is loaded with features. Share feedback or contribute to this awesome CLI.

Any thoughts, let's discuss on twitter

Sharing this article is a great way to educate others like you just did.



If you’ve enjoyed this issue, do consider subscribing to my newsletter.


Subscribe to get more such interesting content !

Tech, Product, Money, Books, Life. Discover stuff, be inspired, and get ahead. Box Piper is on Twitter and Discord. Let's Connect!!

To read more such interesting topics, let's go Home

More Products from the maker of Box Piper:

Follow GitPiper Instagram account. GitPiper is the worlds biggest repository of programming and technology resources. There is nothing you can't find on GitPiper.

Follow SharkTankSeason.com. Dive into the riveting world of Shark Tank Seasons. Explore episodes, pitches, products, investment details, companies, seasons and stories of entrepreneurs seeking investment deals from sharks. Get inspired today!.


Scraper API

More Blogs from the house of Box Piper: