GitHub CLI Cheatsheet

GitHub CLI (gh) brings GitHub to your terminal. Create repositories, manage pull requests, review issues, and run GitHub Actions workflows—all without leaving the command line. This cheatsheet covers the most useful commands for daily development.

Installation Core Commands Aliases & Shortcuts
Installation & Setup
# macOS (Homebrew) brew install gh # Linux (Debian/Ubuntu) sudo apt install gh # Windows (Scoop) scoop install gh # Verify installation gh --version # Authentication (required first step) gh auth login # Choose GitHub.com, SSH/HTTPS, and login via browser
After authentication, `gh` remembers your credentials. You can also use `gh auth status` to check which account you're logged into.
Repository Commands
CommandDescription
gh repo create <name>Create a new repository
gh repo clone <repo>Clone a repository
gh repo fork <repo>Fork a repository
gh repo viewView repository description and README
gh repo listList repositories for a user or org
gh repo delete <repo>Delete a repository (use with caution!)
gh repo archive <repo>Archive a repository
gh repo editEdit repository settings (description, visibility)
# Create a repo from current directory gh repo create my-project --public --source=. --remote=origin --push # Clone a repository with a different name gh repo clone octocat/Spoon-Knife my-fork # View repo in browser (add -w flag) gh repo view --web
Pull Request Commands
CommandDescription
gh pr createCreate a pull request
gh pr listList pull requests
gh pr checkout <number>Checkout a PR locally
gh pr diff <number>View PR changes
gh pr reviewReview a pull request
gh pr mergeMerge a pull request
gh pr statusShow status of current branch's PR
gh pr comment <number>Add a comment to a PR
gh pr ready <number>Mark draft PR as ready for review
# Create a PR with title and body gh pr create --title "Add new feature" --body "Closes #123" --base main # List open PRs assigned to you gh pr list --assignee @me --state open # Review and approve a PR gh pr review 42 --approve --body "Looks good!" # Merge a PR with squash strategy gh pr merge 42 --squash --delete-branch
Issue Commands
CommandDescription
gh issue createCreate an issue
gh issue listList issues
gh issue view <number>View an issue
gh issue close <number>Close an issue
gh issue reopen <number>Reopen an issue
gh issue comment <number>Add a comment
gh issue edit <number>Edit issue title or body
gh issue transfer <number> <repo>Move issue to another repo
# Create an issue with label and assignee gh issue create --title "Bug: login fails" --body "Steps to reproduce..." --label bug --assignee octocat # List issues with label "bug" gh issue list --label bug --state open # View issue in browser gh issue view 42 --web
Workflow & Actions Commands
CommandDescription
gh workflow listList workflows in the repository
gh workflow run <name>Trigger a workflow run
gh workflow view <name>View workflow details
gh run listList recent workflow runs
gh run view <id>View a specific run
gh run watch <id>Watch a run with live logs
gh run rerun <id>Rerun a failed workflow
gh run cancel <id>Cancel a running workflow
# List all workflows gh workflow list # Trigger a workflow with parameters gh workflow run ci.yml --ref main -f environment=staging # View the latest failed run gh run list --status failure --limit 1 # Watch a run's logs in real-time gh run watch 12345678
Gist Commands
CommandDescription
gh gist create <file>Create a new gist
gh gist listList your gists
gh gist view <id>View a gist
gh gist edit <id>Edit a gist
gh gist clone <id>Clone a gist
gh gist delete <id>Delete a gist
# Create a public gist from a file gh gist create script.js --public # Create a private gist with description gh gist create README.md --private --desc "Project notes" # List gists with filters gh gist list --limit 10 --public
Custom Aliases

Create shortcuts for frequently used commands to save time. Aliases can combine multiple gh commands or include shell commands.

CommandDescription
gh alias set <name> <cmd>Create a new alias
gh alias listList all aliases
gh alias delete <name>Delete an alias
# Create alias for "pr list --assignee @me" gh alias set mypr 'pr list --assignee @me' # Create alias for opening issue in browser gh alias set issuew 'issue view $1 --web' # Create alias for listing recent runs gh alias set runs 'run list --limit 5' # Use aliases gh mypr gh issuew 42
Interactive Mode & Useful Flags

Many gh commands run in interactive mode when no arguments are provided, prompting you for title, body, labels, etc. Common flags include:

FlagDescription
--webOpen the result in a browser
--jsonOutput as JSON for scripting
--jqFilter JSON output using jq
--repoSpecify repository (owner/repo)
--labelFilter by labels
--assigneeFilter by assignee (@me for yourself)
--stateFilter by state (open, closed, merged)
--limitLimit number of results
# Output as JSON and filter with jq gh pr list --state open --json title,number --jq '.[] | "#\(.number): \(.title)"' # Open PR diff in browser gh pr diff 42 --web # Work on a different repo without cd-ing gh pr list --repo octocat/Hello-World
Shell Integration

Add gh to your shell prompt to see GitHub context. The gh copilot command (if installed) provides suggestions for gh commands.

# Add to ~/.bashrc or ~/.zshrc for prompt integration eval "$(gh copilot prompt --shell=zsh)" # For zsh eval "$(gh copilot prompt --shell=bash)" # For bash # Show git status with GitHub info gh prompt # Get suggested command explanations gh copilot explain "create a PR with title feat: add search" # Generate gh commands from natural language gh copilot suggest "list all open issues assigned to me"
Productivity Tips
  • Use `.` as a shorthand for current repository - When inside a git repo, you can omit the repo name for most commands.
  • Combine with jq for scripting - Pipe JSON output to jq to extract specific fields for automation.
  • Set default git protocol - `gh auth setup-git` sets up git to use the gh authentication for HTTPS.
  • Use extensions - `gh extension install` installs community extensions. Try `gh repo view` or `gh project`.
  • Create issue from commit - `gh issue create --title "Fix: $(git log -1 --pretty=%s)"`
  • Quick PR from current branch - `gh pr create --fill` fills title and body from commits.
Pro tip: Set GH_PAGER to use a different pager: export GH_PAGER="less -R" for colored output.
Frequently Asked Questions
How do I switch between multiple GitHub accounts?
Use gh auth switch or set the GH_HOST environment variable for different hosts. You can also use gh auth login --hostname enterprise.internal for GitHub Enterprise.
Can I use gh in CI/CD scripts?
Yes! Use gh auth login --with-token < $GITHUB_TOKEN to authenticate in GitHub Actions. The GITHUB_TOKEN is automatically available.
How do I update gh to the latest version?
Run gh update to check for and install updates. On package managers, use your regular update commands (brew upgrade gh, apt upgrade gh).
What's the difference between gh and git?
git is the version control system. gh adds GitHub-specific features on top of git. You still use git for commits, branches, and pushes. gh handles GitHub operations like creating PRs, issues, and releases.
Can I use gh without authentication for public operations?
Some operations work without authentication (like viewing public repos), but most require authentication. Run gh auth login first for full functionality.
How do I list all PRs I've reviewed?
gh pr list --search "reviewed-by:@me" --state all uses GitHub's search syntax to find PRs you've reviewed.
Can I create a PR from a specific commit?
Yes: gh pr create --head branch-name --base main --title "Title" creates a PR from the current branch. To use a specific commit, ensure that's the HEAD of your branch.
How do I get help for a specific command?
Use gh help <command> or gh <command> --help. For example, gh pr create --help shows all options for creating a PR.
Quick Reference Card
# Most frequently used commands gh auth login # First time setup gh repo create # Create a new repo gh repo clone # Clone a repo gh pr create # Create a pull request gh pr list # List open PRs gh pr checkout # Checkout PR locally gh pr merge # Merge a PR gh issue create # Create an issue gh issue list # List open issues gh run list # List workflow runs gh run view # View run logs gh alias set # Create shortcuts gh extension install ... # Install extensions
Previous: Commit Message Guidelines

GitHub CLI turns your terminal into a complete GitHub client. Master these commands to speed up your daily workflow and reduce context switching between browser and terminal.