# 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.

Source: https://www.jpkc.com/db/en/cheatsheets/version-control/gh/

<!-- PROSE:intro -->
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.
<!-- PROSE:intro:end -->

## Auth & Setup

`gh auth login` — Authenticate with GitHub.

```bash
gh auth login
```

`gh auth status` — Show authentication status.

```bash
gh auth status
```

`gh auth logout` — Log out of GitHub.

```bash
gh auth logout
```

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

```bash
gh config set editor vim
```

## Pull Requests

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

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

`gh pr list` — List open pull requests.

```bash
gh pr list
```

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

```bash
gh pr view 42
```

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

```bash
gh pr checkout 42
```

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

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

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

```bash
gh pr diff 42
```

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

```bash
gh pr review 42 --approve
```

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

```bash
gh pr close 42
```

## Issues

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

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

`gh issue list` — List open issues.

```bash
gh issue list --label bug
```

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

```bash
gh issue view 15
```

`gh issue close <number>` — Close an issue.

```bash
gh issue close 15 --reason completed
```

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

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

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

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

## Repositories

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

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

`gh repo clone <repo>` — Clone a repository.

```bash
gh repo clone owner/repo
```

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

```bash
gh repo view --web
```

`gh repo fork <repo>` — Fork a repository.

```bash
gh repo fork owner/repo --clone
```

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

```bash
gh repo list my-org --limit 50
```

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

```bash
gh repo rename new-project-name
```

## Actions & Workflows

`gh run list` — List recent workflow runs.

```bash
gh run list --limit 10
```

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

```bash
gh run view 12345
```

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

```bash
gh run watch 12345
```

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

```bash
gh run rerun 12345 --failed
```

`gh workflow list` — List all workflows in the repository.

```bash
gh workflow list
```

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

```bash
gh workflow run deploy.yml --ref main
```

## Releases & Gists

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

```bash
gh release create v1.0.0 --generate-notes
```

`gh release list` — List releases.

```bash
gh release list
```

`gh release download <tag>` — Download release assets.

```bash
gh release download v1.0.0
```

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

```bash
gh gist create script.sh --public
```

`gh gist list` — List your gists.

```bash
gh gist list
```

## API & Extensions

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

```bash
gh api repos/owner/repo/contributors
```

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

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

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

```bash
gh extension install dlvhdr/gh-dash
```

`gh extension list` — List installed extensions.

```bash
gh extension list
```

`gh browse` — Open the current repository in the browser.

```bash
gh browse
```

<!-- PROSE:outro -->
## 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](https://cli.github.com/) – download and overview
- [GitHub CLI – manual](https://cli.github.com/manual/) – complete command reference
- [GitHub – Wikipedia](https://en.wikipedia.org/wiki/GitHub) – background on the platform
<!-- PROSE:outro:end -->

## Related Commands

- [git](https://www.jpkc.com/db/en/cheatsheets/version-control/git/) – the underlying version control system

