GitHub CLI (gh) — Drive GitHub from the Terminal

Practical guide to the GitHub CLI — manage pull requests, issues, releases, repositories and actions right from the terminal.

The GitHub CLI brings GitHub straight into your terminal: pull requests, issues, releases, repositories, actions and gists – all without opening a browser. gh is GitHub's official tool and speaks the GitHub API natively, including authentication, scripting and extensions. If you already work with git, gh noticeably shortens the path from a local branch to a merged pull request. This guide walks you through the commands you reach for daily, from signing in to raw API access.

Auth & Setup

gh auth login — Authenticate with GitHub.

gh auth login

gh auth status — Show authentication status.

gh auth status

gh auth logout — Log out of GitHub.

gh auth logout

gh config set <key> <value> — Set a configuration value.

gh config set editor vim

Pull Requests

gh pr create — Create a pull request (interactive).

gh pr create --title 'Fix bug' --body 'Description'

gh pr list — List open pull requests.

gh pr list

gh pr view <number> — View a pull request's details.

gh pr view 42

gh pr checkout <number> — Check out a PR branch locally.

gh pr checkout 42

gh pr merge <number> — Merge a pull request.

gh pr merge 42 --squash --delete-branch

gh pr diff <number> — View the diff of a pull request.

gh pr diff 42

gh pr review <number> — Add a review to a pull request.

gh pr review 42 --approve

gh pr close <number> — Close a pull request.

gh pr close 42

Issues

gh issue create — Create a new issue (interactive).

gh issue create --title 'Bug report' --label bug

gh issue list — List open issues.

gh issue list --label bug

gh issue view <number> — View an issue's details.

gh issue view 15

gh issue close <number> — Close an issue.

gh issue close 15 --reason completed

gh issue comment <number> — Add a comment to an issue.

gh issue comment 15 --body 'Fixed in PR #42'

gh issue edit <number> — Edit an issue (title, body, labels, assignees).

gh issue edit 15 --add-label 'priority:high'

Repositories

gh repo create <name> — Create a new repository.

gh repo create my-project --public --clone

gh repo clone <repo> — Clone a repository.

gh repo clone owner/repo

gh repo view — View the current repository's details.

gh repo view --web

gh repo fork <repo> — Fork a repository.

gh repo fork owner/repo --clone

gh repo list <owner> — List repositories for a user or org.

gh repo list my-org --limit 50

gh repo rename <new-name> — Rename the current repository.

gh repo rename new-project-name

Actions & Workflows

gh run list — List recent workflow runs.

gh run list --limit 10

gh run view <run-id> — View details of a workflow run.

gh run view 12345

gh run watch <run-id> — Watch a running workflow in real-time.

gh run watch 12345

gh run rerun <run-id> — Rerun a failed workflow.

gh run rerun 12345 --failed

gh workflow list — List all workflows in the repository.

gh workflow list

gh workflow run <workflow> — Manually trigger a workflow.

gh workflow run deploy.yml --ref main

Releases & Gists

gh release create <tag> — Create a new release.

gh release create v1.0.0 --generate-notes

gh release list — List releases.

gh release list

gh release download <tag> — Download release assets.

gh release download v1.0.0

gh gist create <file> — Create a gist from a file.

gh gist create script.sh --public

gh gist list — List your gists.

gh gist list

API & Extensions

gh api <endpoint> — Make an authenticated GitHub API request.

gh api repos/owner/repo/contributors

gh api <endpoint> --jq '<filter>' — API request with jq filtering.

gh api repos/owner/repo/pulls --jq '.[].title'

gh extension install <repo> — Install a gh CLI extension.

gh extension install dlvhdr/gh-dash

gh extension list — List installed extensions.

gh extension list

gh browse — Open the current repository in the browser.

gh browse

Conclusion

gh bridges local git and the GitHub platform: you handle pull requests, reviews and releases without taking your hands off the keyboard. The tool really shines in scripts and CI/CD pipelines – with gh api and --jq you reach any corner of the GitHub API in a structured way and automate recurring tasks.

Further Reading

  • git – the underlying version control system