The GitHub CLI (gh) is a game-changer because it allows you to manage Pull Requests, Issues, and Repositories without ever leaving your terminal. It effectively bridges the gap between your local Git workflow and GitHub’s cloud features.

🔑 Authentication & Setup

Before doing anything, you need to link your terminal to your GitHub account.

Command Description
gh auth login Start the interactive login process (via browser or token).
gh auth status Check which account you are currently logged into.
gh config set editor <name> Set your preferred text editor for PR descriptions (e.g., nano, vim, code).

📁 Repository Management

Skip the browser when creating or cloning repos.

  • gh repo create <name>: Create a new repository on GitHub.
    • Add --public or --private flags to set visibility.
    • Add --clone to immediately clone it to your machine.
  • gh repo fork <owner/repo>: Create a fork of someone else’s repository and clone it locally.
  • gh repo view --web: Quickly open the current repository’s GitHub page in your default browser.
  • gh repo list <user>: List all repositories belonging to a specific user or organization.

🔀 Pull Requests (The Killer Feature)

This is where the gh CLI saves the most time.

  • gh pr create: Start the process of creating a Pull Request for your current branch.
    • Use --fill to automatically use your git commit message as the PR title/body.
  • gh pr list: See all open PRs in the current repository.
  • gh pr checkout <number>: Check out a specific PR locally to test it. No more manual fetching.
  • gh pr status: View the status of your PRs (reviews, CI/CD checks, etc.).
  • gh pr merge: Interactively merge a PR. You can choose between Merge, Squash, or Rebase.
  • gh pr view --comments: Read the discussion on a PR directly in your terminal.

🐛 Issues

Manage tasks and bugs without context-switching.

  • gh issue list: List the latest issues. Use --author or --label to filter.
  • gh issue create: Create a new issue interactively.
  • gh issue view <number>: View the description and comments of a specific issue.
  • gh issue close <number>: Close an issue once the work is done.

⚡ GitHub Actions & Releases

  • gh run list: See the status of recent GitHub Action workflow runs.
  • gh run watch: Watch a running CI/CD workflow in real-time until it finishes.
  • gh release create <tag>: Package up your code and create a new GitHub Release.
  • gh release download: Download assets from a specific release.

Combine with Git: A very common workflow is:

  1. git commit -m “feat: login”
  2. git push origin head
  3. gh pr create --fill --web (This pushes your code and opens the PR page to double-check before submitting).