GitHub Cheat Sheet

Repositories, pull requests, issues, Actions, releases, and API calls — the day-to-day GitHub workflows behind the platform.

Core DevOps9 sections · 66 commands
⌘K

gh CLI & Auth

6
gh auth login

Authenticate gh CLI

gh auth status

Show current auth state

gh auth token

Print the auth token

gh auth switch

Switch between accounts

gh config set user USERNAME

Set a default account

gh version

gh version

Repositories

8
gh repo create NAME --public

Create a public repo

gh repo create NAME --private --source .

Push an existing dir as a new repo

gh repo clone OWNER/REPO

Clone a repo

gh repo view OWNER/REPO

View repo details in terminal

gh repo fork OWNER/REPO --clone

Fork and clone

gh repo list OWNER --limit 50

List repos

gh repo rename NEW

Rename the current repo

gh repo delete OWNER/REPO

Delete a repo

Pull Requests

10
gh pr create --title "T" --body "D"

Create a PR from the branch

gh pr create --draft

Open a draft PR

gh pr list

List open PRs

gh pr list --state merged

Merged PRs

gh pr view NUMBER

View a PR

gh pr checkout NUMBER

Check out the PR branch locally

gh pr diff

Show the PR diff

gh pr status

PRs touching your branches

gh pr merge NUMBER --merge

Merge a PR (squash/rebase/merge)

gh pr close NUMBER

Close without merging

Issues

6
gh issue create --title "T" --body "D"

Create an issue

gh issue list

List open issues

gh issue list --label bug

Filter by label

gh issue view NUMBER

View an issue

gh issue close NUMBER

Close an issue

gh issue transfer NUMBER TARGET_REPO

Move to another repo

GitHub Actions

10
gh workflow list

Workflows in the repo

gh workflow run CI

Manually trigger a workflow

gh workflow enable/dry-run NAME

Enable or dry-run a workflow

gh run list --workflow CI

Recent runs

gh run list --branch main

Runs on a branch

gh run view RUN_ID

Details and logs of a run

gh run watch RUN_ID

Stream logs until done

gh run rerun RUN_ID --failed

Re-run only failed jobs

gh run cancel RUN_ID

Cancel a run

gh run download RUN_ID

Download run artifacts

Releases & Gists

7
gh release create v1.0.0 --generate-notes

Tag and create a release

gh release create v1.0.0 ./dist/*

Attach build artifacts

gh release list

List releases

gh release view v1.0.0

View a release

gh release download v1.0.0 --pattern '*.tar.gz'

Download matching assets

gh gist create FILE

Create a gist

gh gist list

List your gists

REST API

6
gh api /repos/{owner}/{repo}

Repo metadata

gh api /repos/{owner}/{repo}/actions/runs --paginate | jq '.workflow_runs[] | [.name, .status]'

All workflow runs via API

gh api /repos/{owner}/{repo}/pulls --state=open

Open PRs via API

gh api -X PATCH /repos/{owner}/{repo} -f description='New desc'

Update repo via API

gh api /search/issues -f q='repo:OWNER/REPO is:open'

Search issues

gh api graphql -f query='{repository(owner:"o",name:"r"){stargazerCount}}'

GraphQL query via gh

Settings & Security

8
gh secret list

Repo secrets

gh secret set NAME

Create/update a secret

gh secret set NAME --body "value"

Set secret from a value

gh secret delete NAME

Delete a secret

gh variable list

Repo variables

gh repo set-default

Set the default repo for gh

gh label list

Repo labels

gh alias set prc 'pr create --fill'

Create a gh alias

Codespaces & Copilot

5
gh codespace list

Your codespaces

gh codespace create --repo OWNER/REPO --branch main

Create a codespace

gh codespace ssh

SSH into a codespace

gh codespace ports

Forwarded ports

gh codespace delete -c CODESPACE_NAME

Delete a codespace