GitHub CLI

GitHub CLI

Learn how to use GitHub CLI for command line GitHub tasks.

About the GitHub CLI

GitHub CLI is a command-line tool that brings pull requests, issues, GitHub Actions, and other GitHub features to your terminal, allowing you to do all your work in one place.

GitHub CLI includes features like:

  • View, create, clone, and fork repositories

  • Create, close, edit, and view issues and pull requests

  • Review, compare, and merge pull requests

  • Run, view, and list workflows

  • Create, list, view, and delete releases

  • Create, edit, list, view, and delete gists

  • List, create, delete, and connect to a codespace

  • Retrieve information from the GitHub API

What is the difference between GitHub CLI and Git on the command line?

The Git command line interface (git) lets you work with a local or remote Git repository. The remote repository can be hosted on GitHub or another service.

GitHub CLI (gh) is designed specifically for working with GitHub. It enables you to interact with GitHub through the command line in various ways, as shown in the previous list. If you often work on the command line, you might prefer using GitHub CLI instead of accessing GitHub through a browser. GitHub CLI also simplifies creating scripts to automate GitHub tasks.

Installing GitHub CLI

For instructions on how to install GitHub CLI, visit the GitHub CLI repository and GitHub CLI.

Command prompt showing the GitHub CLI version as 2.64.0 with a release date of 2024-12-20 and a URL link to its release page.

gh

Work smoothly with GitHub using the command line.

gh auth

Authenticate gh and git with GitHub

A terminal window displaying a GitHub authentication process. The user is prompted to select their GitHub usage, protocol preference, and authentication method. A one-time code is provided, with instructions to open a login URL in a browser.

Terminal screenshot showing GitHub authentication steps. It includes a one-time code, authentication confirmation, and successful login message.

Command prompt showing GitHub authentication status and refresh process, with details about the account, token scopes, and a one-time code for logging in.

Core Commands

These commands help you manage repositories, issues, pull requests, and other key features of GitHub.

  1. gh browse
    Open a GitHub repository, issue, pull request, or discussion in your browser.

  2. gh codespace
    Work with GitHub Codespaces, including creating, managing, or connecting to a codespace.

  3. gh gist
    Create, list, edit, or delete GitHub gists.

  4. gh issue
    Manage GitHub issues: create, view, close, reopen, or comment on issues.

  5. gh org
    Manage GitHub organizations: list members, view details, and more.

  6. gh pr
    Manage pull requests: create, view, merge, close, or comment on pull requests.

  7. gh project
    Work with GitHub Projects: manage project boards and items.

  8. gh release
    Manage releases: create, edit, delete, or download release assets.

  9. gh repo
    Interact with GitHub repositories: clone, fork, create, delete, or view information about repositories.

GitHub Actions Commands

These commands are designed to automate workflows and manage GitHub Actions.

  1. gh cache
    Manage GitHub Actions cache: list, delete, or view cache details.

  2. gh run
    View, monitor, or manage GitHub Actions workflow runs.

  3. gh workflow
    Manage workflows: enable, disable, view, or rerun them.

Additional Commands

These commands handle various administrative, configuration, and utility tasks.

  1. gh alias
    Create or manage command shortcuts for the GitHub CLI.

  2. gh api
    Make direct requests to the GitHub API.

  3. gh attestation
    Manage security attestations for GitHub releases or artifacts.

  4. gh completion
    Generate shell completion scripts for the GitHub CLI.

  5. gh config
    Manage GitHub CLI settings, including authentication and preferences.

  6. gh extension
    Install, manage, or create GitHub CLI extensions.

  7. gh gpg-key
    Manage GPG keys: list, add, or delete keys linked to your GitHub account.

  8. gh label
    Manage repository labels: create, edit, or delete them.

  9. gh ruleset
    Work with GitHub's repository or organization rulesets.

  10. gh search
    Search for repositories, issues, pull requests, and more.

  11. gh secret
    Manage GitHub Secrets for repositories or environments.

  12. gh ssh-key
    Manage SSH keys: list, add, or delete keys linked to your GitHub account.

  13. gh status
    Display the current status of GitHub services.

  14. gh variable
    Manage environment variables for GitHub Actions.

Need Help?

For any of these commands, use the --help flag to see details about usage. For example:

gh repo --help

Examples

$ gh issue create
$ gh repo clone cli/cli
$ gh pr checkout 321

References

  1. GitHub CLI Repository
    https://github.com/cli/cli

  2. GitHub CLI Installation Instructions
    https://cli.github.com