GitHub CLI (gh) Tutorial: Repos, Pull Requests, Issues and Actions from the Terminal

The GitHub CLI brings pull requests, issues, Actions and releases to your terminal. In this lesson you will install gh, sign in, and use it for the daily tasks that otherwise need the browser, including checking out a developer’s PR to test it.

Advertisement

📖 What You’ll Learn: what gh is and how it differs from Git, installing and signing in, repository commands, creating, checking out, reviewing and merging pull requests, issues, GitHub Actions runs and artifacts, releases, and power features like gh api, aliases, secrets and extensions.


⌨️ What Is the GitHub CLI?

The GitHub CLI (gh) brings GitHub to your terminal. Git manages your repository; gh manages GitHub: repositories, pull requests, issues, Actions runs, releases and more, without opening the browser.

TaskGitGitHub CLI
Commit, branch, merge✅
Create a repository on GitHubgh repo create
Open and merge pull requestsgh pr create, gh pr merge
Check CI runs and logsgh run list, gh run view --log-failed
Create issues and releasesgh issue create, gh release create

📥 Install

PlatformCommand
Windowswinget install --id GitHub.cli
macOSbrew install gh
Ubuntu / DebianAdd GitHub’s official apt repository, then sudo apt install gh (see the install instructions on cli.github.com)
Fedorasudo dnf install gh

Check: gh --version.


🔐 Sign In

gh auth login

Choose GitHub.com, your preferred protocol (HTTPS or SSH) and Login with a web browser, then enter the one-time code shown in the terminal. gh can also configure Git to use it as a credential helper, so git push over HTTPS just works.

gh auth status          # who am I and which scopes?

📁 Repositories

gh repo create my-tests --private --clone        # new repo on GitHub and clone it
gh repo create --source=. --public --push        # publish the current folder
gh repo clone acme/qa-platform
gh repo fork acme/qa-platform --clone            # fork + clone + upstream remote
gh repo view --web                               # open the repo in the browser

See push an existing project and forks.


🔃 Pull Requests

gh pr create --title "Add login tests" --body "Closes #42" --reviewer ravi-kumar --label tests
gh pr create --fill --draft                # title and body from your commits, as a draft
gh pr list                                  # open PRs
gh pr status                                # PRs that involve you
gh pr checkout 57                           # check out PR #57 locally to test it
gh pr diff 57
gh pr review 57 --approve                   # or --request-changes -b "Please add a test"
gh pr checks 57                             # CI status
gh pr merge 57 --squash --delete-branch

💡 Tip: gh pr checkout <number> is the fastest way for a tester to run a developer’s change locally before it is merged (pull requests, code review).


🐞 Issues

gh issue create --title "Checkout total ignores discount" --label bug --assignee @me
gh issue list --label bug --state open
gh issue view 42 --comments
gh issue close 42 --comment "Fixed in #57"

⚙️ GitHub Actions

gh workflow list
gh workflow run ci.yml -f browser=firefox      # trigger workflow_dispatch with an input
gh run list --limit 5
gh run watch                                    # follow the latest run live
gh run view 123456789 --log-failed              # only logs of failed steps
gh run download 123456789 -n playwright-report  # download an artifact
gh run rerun 123456789 --failed                 # re-run failed jobs

These pair with workflow syntax and artifacts.


🏷️ Releases

gh release create v1.2.0 --generate-notes            # release from a tag with auto notes
gh release create v1.2.0 ./dist/report.zip --title "v1.2.0"
gh release list

See Git tags and releases.


🧰 Power Features

gh api repos/acme/qa-platform/pulls --jq '.[].title'   # call any REST endpoint, filter with jq
gh alias set prs 'pr list --author @me'                  # create shortcuts: gh prs
gh secret set TEST_PASSWORD                              # set an Actions secret (prompts for value)
gh variable set BASE_URL --body https://staging.example.com
gh extension install dlvhdr/gh-dash                       # extensions add new commands (here: a PR and issue dashboard)

Secrets and variables are explained in secrets and environments.


📝 Assignment

  1. Install gh and log in with gh auth login.
  2. Create a new private repository from the terminal with gh repo create.
  3. Create a branch, commit, and open a PR with gh pr create --fill; check it with gh pr checks and merge it with gh pr merge --squash --delete-branch.
  4. Create and close an issue from the terminal.
  5. Trigger a workflow_dispatch workflow with gh workflow run and follow it with gh run watch.
  6. Create an alias for a command you use often.

❓ FAQ

🤔 What is GitHub CLI?

The official command-line tool gh for working with GitHub: repositories, pull requests, issues, Actions, releases and the API from your terminal.

🤔 How do I install GitHub CLI on Windows?

Run winget install --id GitHub.cli (or download the installer from cli.github.com), then gh auth login.

🤔 How do I create a pull request from the command line?

Push your branch and run gh pr create (add --fill to use your commit messages).

🤔 How do I check GitHub Actions logs from the terminal?

gh run list to find the run, then gh run view <id> --log-failed or gh run watch.

🤔 Is GitHub CLI the same as Git?

No. Git works with repositories and history; GitHub CLI works with GitHub features such as PRs, issues and Actions. You use them together.


🎯 Next Steps

🎬 Learn Git and GitHub step by step: watch the series on YouTube!

Subscribe to SqaToolsByDY • Practice on sqatools.in

Leave a Comment