GitHub CLI cheat sheet
/
Jump to section10
1 Set-up, 6
gh auth login- Log in to GitHub.
gh auth status- Show which accounts are logged in.
gh auth switch- Switch to another account.
gh auth refresh -s scope- Add a scope to your token.
gh config set editor nvim- Set the editor gh opens.
gh alias set name 'cmd'- Make a shortcut for a command.
2 Repositories, 7
gh repo clone owner/repo- Clone a repository.
gh repo create- Create a repository interactively.
gh repo fork owner/repo --clone- Fork a repo and clone the fork.
gh repo sync owner/fork- Update your fork from upstream.
gh repo set-default- Choose the repo gh commands use.
gh browse- Open the repo on GitHub.
gh browse file:line- Open a file at a line on GitHub.
3 Opening a pull request, 5
gh pr create- Open a PR from the current branch.
gh pr create --fill- Fill title and body from commits.
gh pr create --draft- Open a draft PR.
gh pr create --web- Finish the PR in the browser.
gh pr ready- Mark a draft PR ready for review.
4 Finding and reading pull requests, 7
gh pr status- Your PRs and those awaiting you.
gh pr list- List open PRs.
gh pr list --author "@me"- List the PRs you opened.
gh pr view n- Show a PR's details.
gh pr view n --comments- Show a PR with its comments.
gh pr diff n- Show a PR's diff.
gh pr checkout n- Check out a PR's branch locally.
5 Reviewing and merging, 10
gh pr checks- Show a PR's CI checks.
gh pr checks --watch- Watch the checks until they end.
gh pr review --approve- Approve a PR.
gh pr review -r -b "text"- Request changes on a PR.
gh pr comment -b "text"- Comment on a PR.
gh pr edit --add-reviewer user- Ask someone to review a PR.
gh pr edit --add-label name- Add a label to a PR.
gh pr merge --squash- Squash and merge a PR.
gh pr merge --auto --squash- Merge once the checks pass.
gh pr close n- Close a PR without merging.
6 Issues, 7
gh issue list- List open issues.
gh issue list --assignee "@me"- List issues assigned to you.
gh issue create- Open a new issue.
gh issue view n- Show an issue's details.
gh issue comment n -b "text"- Comment on an issue.
gh issue develop n --checkout- Start a branch for an issue.
gh issue close n- Close an issue.
7 GitHub Actions, 8
gh run list- List recent workflow runs.
gh run list --branch main- List the runs on one branch.
gh run watch- Watch a run until it finishes.
gh run view --log-failed- Show the logs of failed steps.
gh run rerun --failed- Re-run only the failed jobs.
gh run download- Download a run's artefacts.
gh workflow list- List the repo's workflows.
gh workflow run name.yml- Start a workflow by hand.
8 Secrets and variables, 3
gh secret list- List the repo's Actions secrets.
gh secret set NAME- Set an Actions secret.
gh variable set NAME- Set an Actions variable.
9 Releases and gists, 5
gh release list- List releases.
gh release create v1- Create a release from a tag.
gh release create v1 --generate-notes- Write notes from merged PRs.
gh release download v1- Download a release's assets.
gh gist create file- Share a file as a gist.
10 Search, scripting and the API, 8
gh status- Your PRs, issues and mentions.
gh search prs --review-requested=@me- PRs that asked for your review.
gh search repos term- Search repositories on GitHub.
gh pr list --json number,title- Print chosen fields as JSON.
gh pr list --json url --jq '.[].url'- Filter JSON output with jq.
gh api repos/{owner}/{repo}- Call the REST API.
gh api graphql -f query='…'- Run a GraphQL query.
gh extension install owner/gh-ext- Install a gh extension.