Everyday gh Commands

Everyday gh Commands for Repositories, Issues and Pull Requests

Inside a clone, gh 29 infers the repository from the origin remote; elsewhere, name it with -R OWNER/REPO. The commands you will use most:

The gh commands used most in this chapter
Area Commands
Repositories gh repo clone, gh repo create --source ., gh browse
Issues and pull requests gh issue create/list/view, gh pr create/checkout/merge
Actions and the API gh run list, gh run watch, gh api repos/{owner}/{repo}

Pointed at gh's own repository, a few of them read like this:

Looking around a public repository with ghShell
gh repo view cli/cli --json description,stargazerCount,licenseInfo \
  --jq '"\(.description)\n\(.stargazerCount) stars, \(.licenseInfo.name)"'
gh issue list -R cli/cli --label bug --limit 3
Output
GitHub’s official command line tool
46401 stars, MIT License
Showing 3 of 264 issues in cli/cli that match your search
ID      TITLE                                      LABELS                     UPDATED
#14394  `gh pr list` with flags fails JSON par...  bug, priority-3            about 10 days ago
#14389  `gh release create` does not recognise...  bug, priority-2            about 16 days ago
#14386  `gh issue create` issue type supports ...  bug, priority-2, gh-issue  about 14 days ago

The table layout appears only on a terminal; piped into another program, gh prints tab-separated columns instead, and --json with --jq (as in the first command) gives stable fields for scripts. {owner} and {repo} in a gh api path are filled in from the current clone. gh alias set bugs 'issue list --label bug' saves typing.