DEV Community

Cover image for GitHub CLI
chandra penugonda
chandra penugonda

Posted on • Updated on

GitHub CLI

Github just released a new command line tool called the GitHub CLI. It brings pull requests, issues, and other GitHub concepts to the terminal next to where you are already working.

GitHub CLI ??

gh is GitHub on the command line. It brings pull requests, issues, and other GitHub concepts to the terminal next to where you are already working.GitHub CLI is available for download on Linux, MacOS, Windows machines

Installation

For MacoS, gh is available via Homebrew and MacPorts.
brew install gh
sudo port install gh
Enter fullscreen mode Exit fullscreen mode
For 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
Enter fullscreen mode Exit fullscreen mode
  • chocolatey
choco install gh  
Enter fullscreen mode Exit fullscreen mode
For Linux
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-key C99B11DEB97541F0
sudo apt-add-repository https://cli.github.com/packages
sudo apt update
sudo apt install gh
Enter fullscreen mode Exit fullscreen mode

Authentication:

Use below command to authenticate with your GitHub account. gh will respect tokens set using GITHUB_TOKEN.

gh auth login
Enter fullscreen mode Exit fullscreen mode
For GitHub Enterprise instance
gh auth login --hostname <hostname>
Enter fullscreen mode Exit fullscreen mode

You will be prompted to either authenticate using your browser, or to paste a token.

View Authentication status

gh auth status [flags]
Enter fullscreen mode Exit fullscreen mode
Now we have Successfully installed the GitHub CLI. lets clone a repo and raise a PR
gh repo clone @username/@reponame
Enter fullscreen mode Exit fullscreen mode

By this time, GitHub will ask to authenticate.Once Authenticated navigate to cloned repo

cd @reponame
Enter fullscreen mode Exit fullscreen mode
Creating a new branch ,create a file in this branch and push it
git checkout -b new_branch
touch test.js
echo "Testing" >> test.js
git push origin new_branch
Enter fullscreen mode Exit fullscreen mode
To create a PR
gh pr create
Enter fullscreen mode Exit fullscreen mode

Answering simple questions to above command creates a PR

To know all pull requests
gh pr checkout {<pull request number> | <url> | <branch>} [flags]
Enter fullscreen mode Exit fullscreen mode
To view Diff
gh pr diff
Enter fullscreen mode Exit fullscreen mode
To merge a PR
gh pr merge
Enter fullscreen mode Exit fullscreen mode
To know if all test cases are passing
gh pr checks
Enter fullscreen mode Exit fullscreen mode
To know open issues assigned to you.
gh issue status
Enter fullscreen mode Exit fullscreen mode

By using below command , you can see any issues assigned to you or any issues that mentioned you

To know all issues
gh issue list
gh issue list --state open
gh issue list --state closed
Enter fullscreen mode Exit fullscreen mode

By using below command , you can see all issues

To create a PR
gh pr create
Enter fullscreen mode Exit fullscreen mode

Answering simple questions to above command creates a PR

How to manage Aliases with github cli

A alias is essentially nothing more than a keyboard shortcut, an abbreviation, a means of avoiding typing a long command sequence

Creating an Alias
gh alias set
Enter fullscreen mode Exit fullscreen mode
Share your alias with gist
gh alias list | gh gist create
Enter fullscreen mode Exit fullscreen mode

To access the GitHub API directly

gh api
Enter fullscreen mode Exit fullscreen mode

Resources

GitHub CLI 1.0

Top comments (0)