What is GitHub CLI (gh)?
GitHub CLI, known as gh, is the official command-line tool for GitHub. It brings the power of GitHub to your terminal, allowing you to manage repositories, work with issues, handle pull requests, and interact with GitHub Actions without ever leaving your command-line environment. It’s designed to streamline your workflow, reduce context switching, and make scripting and automation seamless.
Key Features
- Full Repository Management: Create, clone, fork, and view repositories directly from the CLI.
- Issues and Pull Requests: List, view, create, and manage issues and pull requests. You can even check out PR branches, review code, and merge them.
- GitHub Actions Integration: View workflow status, watch live logs, and download artifacts from workflow runs.
- Gists and Releases: Create and manage gists, and handle software releases, including uploading assets.
- Extensibility: Create custom commands and aliases to tailor
ghto your specific needs and workflows. - Authentication: Securely authenticates with your GitHub account using browser-based or token-based flows.
Use Cases
- Automation & Scripting: Automate repetitive tasks like creating pull requests, setting up new repositories, or bulk-managing issues.
- CI/CD Integration: Use
ghin your CI/CD pipelines to interact with GitHub, such as creating a release after a successful build. - Terminal-Centric Workflow: For developers who live in the terminal,
ghprovides a way to perform nearly all GitHub-related tasks without a GUI. - Quick Status Checks: Quickly check the status of a pull request or see the latest issues for a project with a single command.
Getting Started
Here’s a simple “Hello World” style guide to get you started with gh.
- Installation:
On macOS, you can use Homebrew:
brew install ghFor other systems like Windows or Linux, refer to the official installation guide.
- Authentication:
Log in to your GitHub account. This command will open a browser window for you to authorize the CLI.
gh auth login - Create and Clone a Repository:
Let’s create a new public repository and clone it.
# Create a new repository on GitHub gh repo create my-cli-app --public --source=. --remote=origin # Clone an existing repository gh repo clone cli/cli - List Issues:
Navigate into a cloned repository’s directory and list its open issues.
cd cli gh issue list
Pricing
GitHub CLI (gh) is completely free and open-source, distributed under the MIT License. You can use it without any cost for both personal and commercial projects.
Community
As an official GitHub tool, gh has a massive and active community. The project boasts tens of thousands of stars on GitHub and is widely praised for its robust feature set and for significantly improving developer productivity. Feedback is overwhelmingly positive, and the tool is considered mature and stable for daily use.