#15 GitHub CLI
gh repo, gh pr, gh issue
What is gh?
gh is the official GitHub command-line tool. It lets you do from the terminal everything you would normally do on the GitHub website: create repositories, manage pull requests, issues, and much more.
gh auth -- Authenticate
Before using gh, you need to log in to your GitHub account. Use gh auth login to start the authentication process, then verify with gh auth status:
$ gh auth status
github.com
✓ Logged in to github.com account alice (keyring)
- Active account: true
- Git operations protocol: https
- Token: gho_****
- Token scopes: gist, read:org, repo, workflowgh repo -- Manage repositories
Create a new repository directly from the terminal with gh repo create:
$ gh repo create my-app --public
✓ Created repository alice/my-app on GitHub
https://github.com/alice/my-appClone an existing repository with gh repo clone:
$ gh repo clone alice/my-app
Cloning into 'my-app'...
done.gh pr -- Manage Pull Requests
Create a pull request from your current branch:
$ gh pr create --title "Add feature" --body "Description"
Creating pull request for feature into main in alice/my-project
https://github.com/alice/my-project/pull/1List open PRs with gh pr list:
$ gh pr list
Showing 2 of 2 open pull requests in alice/my-project
#2 Fix bug fix-bug OPEN
#1 Add feature feature OPENYou can also use gh pr view to see PR details and gh pr merge to merge it.
gh issue -- Manage issues
Issues are used to report bugs or request features. Create one from the terminal:
$ gh issue create --title "Bug report" --body "Details"
Creating issue in alice/my-project
https://github.com/alice/my-project/issues/1List open issues:
$ gh issue list
Showing 1 of 1 open issue in alice/my-project
#1 Bug report OPEN about 1 minute agogh workflow -- Manage workflows
GitHub Actions lets you automate tasks (tests, deployment, etc.). With gh workflow, you can list and trigger these workflows:
$ gh workflow list
Deploy deploy.yml active
Tests tests.yml active$ gh workflow run tests.yml
✓ Created workflow_dispatch event for tests.yml
To see runs for this workflow, try: gh run list --workflow=tests.ymlSummary
gh auth login # Log in
gh auth status # Check connection
gh repo create name --public # Create a repository
gh repo clone user/repo # Clone a repository
gh pr create --title "..." --body "..." # Create a PR
gh pr list # List PRs
gh issue create --title "..." --body "..." # Create an issue
gh issue list # List issues
gh workflow list # List workflows
gh workflow run file.yml # Trigger a workflowYour turn
Try the GitHub CLI commands in the terminal below. Start with gh auth status to check your connection.