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 logingh auth status — Show authentication status.
gh auth statusgh auth logout — Log out of GitHub.
gh auth logoutgh config set <key> <value> — Set a configuration value.
gh config set editor vimPull 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 listgh pr view <number> — View a pull request's details.
gh pr view 42gh pr checkout <number> — Check out a PR branch locally.
gh pr checkout 42gh pr merge <number> — Merge a pull request.
gh pr merge 42 --squash --delete-branchgh pr diff <number> — View the diff of a pull request.
gh pr diff 42gh pr review <number> — Add a review to a pull request.
gh pr review 42 --approvegh pr close <number> — Close a pull request.
gh pr close 42Issues
gh issue create — Create a new issue (interactive).
gh issue create --title 'Bug report' --label buggh issue list — List open issues.
gh issue list --label buggh issue view <number> — View an issue's details.
gh issue view 15gh issue close <number> — Close an issue.
gh issue close 15 --reason completedgh 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 --clonegh repo clone <repo> — Clone a repository.
gh repo clone owner/repogh repo view — View the current repository's details.
gh repo view --webgh repo fork <repo> — Fork a repository.
gh repo fork owner/repo --clonegh repo list <owner> — List repositories for a user or org.
gh repo list my-org --limit 50gh repo rename <new-name> — Rename the current repository.
gh repo rename new-project-nameActions & Workflows
gh run list — List recent workflow runs.
gh run list --limit 10gh run view <run-id> — View details of a workflow run.
gh run view 12345gh run watch <run-id> — Watch a running workflow in real-time.
gh run watch 12345gh run rerun <run-id> — Rerun a failed workflow.
gh run rerun 12345 --failedgh workflow list — List all workflows in the repository.
gh workflow listgh workflow run <workflow> — Manually trigger a workflow.
gh workflow run deploy.yml --ref mainReleases & Gists
gh release create <tag> — Create a new release.
gh release create v1.0.0 --generate-notesgh release list — List releases.
gh release listgh release download <tag> — Download release assets.
gh release download v1.0.0gh gist create <file> — Create a gist from a file.
gh gist create script.sh --publicgh gist list — List your gists.
gh gist listAPI & Extensions
gh api <endpoint> — Make an authenticated GitHub API request.
gh api repos/owner/repo/contributorsgh 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-dashgh extension list — List installed extensions.
gh extension listgh 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
- GitHub CLI – official website – download and overview
- GitHub CLI – manual – complete command reference
- GitHub – Wikipedia – background on the platform
Related Commands
- git – the underlying version control system