GitHub CLI Guide
This guide provides an overview of using GitHub CLI (gh) to manage pull requests and other GitHub tasks from the command line.
Table of Contents
Installation
To install GitHub CLI, follow the instructions for your operating system:
- macOS:
brew install gh - Windows:
winget install --id GitHub.cli - Linux: Refer to GitHub CLI installation guide
Authentication
Authenticate with your GitHub account:
gh auth login
Follow the prompts to complete the authentication process.
Pull Requests
Creating a Pull Request
To create a new pull request:
gh pr create
This command will prompt you for the necessary information, or you can provide options directly:
gh pr create --title "Your PR Title" --body "Description of changes" --base main
Listing Pull Requests
To list pull requests:
gh pr list
Filter pull requests:
gh pr list --state open --label bug --assignee @me
Checking Out a Pull Request
To check out a pull request locally:
gh pr checkout <pr-number>
Reviewing a Pull Request
To start a review:
gh pr review <pr-number>
Add your review comments and submit:
gh pr review <pr-number> --comment "Great work! A few minor suggestions..."
Approve a pull request:
gh pr review <pr-number> --approve
Request changes:
gh pr review <pr-number> --request-changes
Merging a Pull Request
To merge a pull request:
gh pr merge <pr-number>
You can specify the merge method:
gh pr merge <pr-number> --merge # Creates a merge commit
gh pr merge <pr-number> --squash # Squashes commits
gh pr merge <pr-number> --rebase # Rebases commits
Issues
Create a new issue:
gh issue create --title "Bug: Login Form Not Working" --body "Description of the issue"
List issues:
gh issue list
Close an issue:
gh issue close <issue-number>
Repositories
Clone a repository:
gh repo clone <owner>/<repo-name>
Create a new repository:
gh repo create <repo-name> --public --clone
Advanced Usage
View command help:
gh <command> --help
Use GitHub CLI in scripts:
gh pr list --json number,title,author --jq '.[] | [.number, .title, .author.login] | @tsv'
This guide covers the basics of using GitHub CLI. For more detailed information and advanced usage, refer to the official GitHub CLI documentation.