Installation (Debian / Ubuntu)

sudo mkdir -p -m 755 /etc/apt/keyrings

wget -qO- https://cli.github.com/packages/githubcli-archive-keyring.gpg \
    | sudo tee /etc/apt/keyrings/githubcli-archive-keyring.gpg > /dev/null

echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg]
  https://cli.github.com/packages stable main" \
  | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null

sudo apt update && sudo apt install gh

gh --version          # verify

Auth & Setup

gh auth login                 # authenticate (browser or token)
gh auth status                # who am I / which accounts
gh auth switch                # switch between logged-in accounts
gh auth token                 # print current token (feed to other tools)
gh auth refresh -s project    # add an OAuth scope (e.g. project)
gh auth setup-git             # use gh as git's HTTPS credential helper

Repositories

gh repo create my-app --private --source=. --remote=origin --push
gh repo clone owner/name                 # clone (owner/name or URL)
gh repo fork --clone                      # fork + clone in one step
gh repo view --web                        # open repo in browser
gh repo view owner/name                   # README + metadata in terminal
gh repo list owner --limit 50             # list a user/org's repos
gh repo set-default owner/name            # pin the default repo for this dir
gh browse                                 # open current repo; `gh browse 42` β†’ issue/PR
gh browse src/main.c:120                  # open a file at a line on GitHub

Issues

gh issue create -t "Title" -b "Body" -l bug -a @me   # create with title/body/label/assignee
gh issue list --state open --label bug --assignee @me
gh issue view 42                          # read #42; add --web for browser
gh issue status                           # issues relevant to you
gh issue comment 42 -b "On it."
gh issue edit 42 --add-label wip --milestone v2.0
gh issue close 42 --comment "Fixed in #51."
gh issue reopen 42
gh issue develop 42 --checkout            # create+checkout a branch for issue #42

Pull requests

gh pr create -t "Title" -b "Closes #42."  # open a PR from current branch
gh pr create --fill                        # title/body from commits
gh pr create --draft                       # open as draft
gh pr list --state open --label bug
gh pr status                               # PRs: yours, assigned, needing review
gh pr view 51                              # add --web for browser
gh pr checkout 51                          # check out PR #51 locally to test it
gh pr diff 51                              # view the diff
gh pr checks 51                            # watch CI status checks
gh pr review 51 --approve                  # or --request-changes -b "..." / --comment
gh pr comment 51 -b "LGTM."
gh pr ready 51                             # mark a draft as ready for review
gh pr merge 51 --squash --delete-branch    # --merge / --rebase / --auto

Releases

gh release create v1.2.0 --generate-notes            # tag + auto changelog
gh release create v1.2.0 ./dist/*.tar.gz -t "v1.2.0" # attach build assets
gh release list
gh release view v1.2.0
gh release download v1.2.0 --pattern "*.tar.gz"
gh release upload v1.2.0 ./extra-asset.zip
gh release delete v1.2.0 --cleanup-tag

GitHub Actions (Workflows & Runs)

gh workflow list                          # workflows in this repo
gh workflow run deploy.yml -f env=prod    # manually trigger (workflow_dispatch)
gh workflow enable deploy.yml             # or disable
gh run list --workflow deploy.yml         # recent runs
gh run view 12345 --log                   # full logs
gh run view 12345 --log-failed            # only failed steps
gh run watch 12345                        # live status until it finishes
gh run rerun 12345 --failed               # retry only the failed jobs
gh run download 12345                     # download run artifacts