Search for a command to run...
A comprehensive guide for installing and configuring GitHub CLI (gh) on different operating systems
GitHub CLI (gh
) is GitHub's official command-line tool that brings GitHub to your terminal. It reduces the need to switch between the browser and terminal by enabling you to manage GitHub workflows directly from the command line.
# Add GitHub CLI repository
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
# Update package list and install
sudo apt update
sudo apt install gh -y
After installing GitHub CLI, authenticate with your GitHub account:
# Start the login process
gh auth login
# Follow the interactive prompts to:
# 1. Select GitHub.com or GitHub Enterprise Server
# 2. Choose your preferred protocol (HTTPS or SSH)
# 3. Authenticate through your browser or with a token
Verify the installation by checking the GitHub CLI version:
gh --version
# Clone a repository
gh repo clone owner/repo
# Create a new repository
gh repo create [name] [flags]
# Fork a repository
gh repo fork [repository]
# View repository
gh repo view [repository]
# Create an issue
gh issue create
# List issues
gh issue list
# View an issue
gh issue view [issue-number]
# Close an issue
gh issue close [issue-number]
# Create a pull request
gh pr create
# List pull requests
gh pr list
# Check out a pull request locally
gh pr checkout [pr-number]
# View a pull request
gh pr view [pr-number]
Authentication Failed
Command Not Found
API Rate Limiting
GitHub CLI respects several environment variables:
# Set default GitHub host
export GH_HOST="github.com"
# Set default editor
export GH_EDITOR="vim"
# Set default browser
export GH_BROWSER="firefox"